sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Confusing analyzer error message when naming variable the name of a type

Open srawlins opened this issue 7 years ago • 1 comments

Take this code:

final int int = 7;

void main() {
  final num num = 7;
}

This results in a strange error:

  error • int isn't a type at 22553.dart:1:7 • not_a_type
  error • Local variable 'num' can't be referenced before it is declared at 22553.dart:4:9 • referenced_before_declaration

The second error makes sense, sort of. But in the first error, the message is bogus.

srawlins avatar Jun 28 '18 22:06 srawlins

Just verified that it still behaviors that way.

It would be better to say something like "The type '{0}' can't be used here because it's shadowed by the variable name.", and to use the same message in both cases.

bwilkerson avatar Jun 09 '25 18:06 bwilkerson