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

Front end: Confusing error message with Null typed condition #41384

Open
eernstg opened this issue Apr 8, 2020 · 2 comments
Open

Front end: Confusing error message with Null typed condition #41384

eernstg opened this issue Apr 8, 2020 · 2 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. improve-diagnostics Related to the quality of diagnostic messages

Comments

@eernstg
Copy link
Member

eernstg commented Apr 8, 2020

Consider the following program:

void main() {
  if (null) {}
}

At commit 28c4c6c (Apr 8), we get the following response from dart with null-safety:

> dart --enable-experiment=non-nullable n010.dart
lang/dart/scratch/202004(master %)$ head_test_dart --enable-experiment=non-nullable n010.dart
n010.dart:2:7: Error: A value of type 'Null?' can't be assigned to a variable of type 'bool'.
  if (null) {}
      ^

The type Null? seems to arise because its nullability is 'nullable', but the notation is confusing because there is no ? on Null in any relevant location in the program. The reference to a variable is misleading because there are no variables.

A similar error message is emitted if we introduce Null n = null and use if (n) {}.

@eernstg eernstg added area-front-end Use area-front-end for front end / CFE / kernel format related issues. improve-diagnostics Related to the quality of diagnostic messages labels Apr 8, 2020
@eernstg eernstg changed the title Front end: Confusing error message Front end: Confusing error message with Null typed condition Apr 8, 2020
@chloestefantsova
Copy link
Contributor

That textual representation originates from Null being represented as an InterfaceType in Kernel. We have plans to use a dedicated Kernel node type for Null which would receive its own textual representation. The GitHub issue for that upcoming change is #40122.

@eernstg
Copy link
Member Author

eernstg commented Apr 8, 2020

OK! @stefantsov, I'll leave it to you to close this issue if you consider it to be redundant, given #40122.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. improve-diagnostics Related to the quality of diagnostic messages
Projects
None yet
Development

No branches or pull requests

2 participants