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

non-nullable promotion on assignment not working #39562

Closed
mit-mit opened this issue Nov 28, 2019 · 6 comments
Closed

non-nullable promotion on assignment not working #39562

mit-mit opened this issue Nov 28, 2019 · 6 comments
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

@mit-mit
Copy link
Member

mit-mit commented Nov 28, 2019

main.dart:

void main() {
  int? a;
  a = 42;
  int b = a;
  print(b);
}
$ ./dart-sdk7/bin/dartanalyzer --enable-experiment=non-nullable main.dart
Analyzing main.dart...
  error • A value of type 'int?' can't be assigned to a variable of type 'int'. • main.dart:4:11 • invalid_assignment
1 error found.
| ~/tmp @ mit-macbookpro3 (mit)
$ ./dart-sdk7/bin/dartanalyzer --version
dartanalyzer version 2.7.0-dev.1.0
| ~/tmp @ mit-macbookpro3 (mit)
@mit-mit mit-mit added the NNBD Issues related to NNBD Release label Nov 28, 2019
@mit-mit
Copy link
Member Author

mit-mit commented Nov 28, 2019

cc @lrhn this is expected to work, right?

@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Nov 28, 2019
@lrhn
Copy link
Member

lrhn commented Nov 28, 2019

I expect it to work, and I'm hitting it now while migrating dart:_http.

Being nullable is always "interesting". A lot of code paths have a shape like:

Foo? something;
if (somethingElse) {
  something = computeFoo();
  bar = something.whatnot();
}

It's too annoying to have to introduce a new variable when you already have a local variable.

@mit-mit
Copy link
Member Author

mit-mit commented Nov 28, 2019

cc @johnniwinther @stereotype441

@stereotype441
Copy link
Member

Agreed. The non-nullable analogue of the declared type needs to be a type of interest. This is on my list to work on.

@sortie
Copy link
Contributor

sortie commented Jan 27, 2020

This pattern came up a bunch when migrating dart:io and the code could be made nicer once this feature is implemented.

dart-bot pushed a commit that referenced this issue Apr 18, 2020
Bug: #39562
Change-Id: Id55224199f64a8f01b14937ddda6963aff24140c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143661
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
@scheglov scheglov self-assigned this Apr 21, 2020
@scheglov
Copy link
Contributor

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

5 participants