dart-lang / language

Design of the Dart language
Other
2.66k stars 205 forks source link

Static analysis in null-aware elements #4118

Closed chloestefantsova closed 3 weeks ago

chloestefantsova commented 3 weeks ago

Consider the following excerpt from a test:

  var map = <int, int>{
    0: ? e - 1,
    1: ? (e) + 0,
    ? e + 1: 2,
    ? (e) + 2: 3,
  };

https://github.com/dart-lang/co19/blob/c09143e5adfb0779a9708792696b6ee64fbec0b3/LanguageFeatures/Control-flow-collections/Null-aware-elements/syntax_A03_t01.dart#L51-L56

In it, the variable e has static type int?. It is my understanding that the expression e - 1 in the line containing 0: ? e - 1, is analyzed independently from the null-aware marker ? preceding it. In that expression, e has static type int?, which makes the expression e - 1 a compile-time error.

Should the line containing 0: ? e - 1, trigger a compile-time error message?

/cc @eernstg @sgrekhov

eernstg commented 3 weeks ago

Looks like a missing declaration of an extension member operator -.

sgrekhov commented 3 weeks ago

https://github.com/dart-lang/co19/pull/2918

chloestefantsova commented 3 weeks ago

It looks like the question is resolved. Thanks, everyone!