Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer extension method resolution is incorrect for nullable types #40931

Closed
leafpetersen opened this issue Mar 9, 2020 · 1 comment
Closed
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. NNBD Issues related to NNBD Release

Comments

@leafpetersen
Copy link
Member

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

@leafpetersen leafpetersen added NNBD Issues related to NNBD Release area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Mar 9, 2020
@scheglov scheglov self-assigned this Mar 9, 2020
@scheglov
Copy link
Contributor

scheglov commented Mar 9, 2020

https://dart-review.googlesource.com/c/sdk/+/138790

Well, method body inference is not specified, so I don't know for sure if I'm doing it right.
But this CL fixes the test case.

dart-bot pushed a commit that referenced this issue Mar 10, 2020
Bug: #40931
Change-Id: I483c3febad236b366f911f38339c712dd928cfcf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138790
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. NNBD Issues related to NNBD Release
Projects
None yet
Development

No branches or pull requests

2 participants