Skip to content

Analyzer extension method resolution is incorrect for nullable types #40931

@leafpetersen

Description

@leafpetersen

The following program resolves an extension on T? to an int? receiver, which should result in T being resolved to int, and hence the return type of foo being int:

extension Test<T> on T? {
  T get foo => this!;
}

void main() {
  int? a;
  a.foo.isEven;
}

The analyzer currently emits an incorrect error on this indicating that the return type of foo is nullable.

leafp-macbookpro:tmp leafp$ /Users/leafp/src/dart-repo/sdk/xcodebuild/ReleaseX64NNBD/dart-sdk/bin/dartanalyzer --enable-experiment=non-nullable ~/tmp/test4.dart
Analyzing /Users/leafp/tmp/test4.dart...
  error • The expression is nullable and must be null-checked before it can be used. • test4.dart:26:3 • unchecked_use_of_nullable_value

cc @scheglov

Metadata

Metadata

Assignees

Labels

NNBDIssues related to NNBD Releaselegacy-area-analyzerUse area-devexp instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions