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

Parser does not allow ! before . (NNBD) #37111

Closed
stereotype441 opened this issue May 29, 2019 · 4 comments
Closed

Parser does not allow ! before . (NNBD) #37111

stereotype441 opened this issue May 29, 2019 · 4 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@stereotype441
Copy link
Member

With --enable-experiment=non-nullable, the following code has a parse error:

class A {
  int? b = 1;
}
main() {
  var a = A();
  print(a!.b); // ERROR: Expected to find ')'
}

Note: I discovered this while trying to confirm whether we support ! in cascade expressions, e.g. a..foo()!.bar=3; (see discussion at dart-lang/language#293 (comment)). So we should double check this case too when fixing the bug.

@stereotype441 stereotype441 added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label May 29, 2019
@stereotype441
Copy link
Member Author

@danrubel

@eernstg
Copy link
Member

eernstg commented May 29, 2019

Also note that this CL contains a Dart.g grammar file that builds on one of Lasse's proposals to include support for ! as a selector.

This means that there is a complete grammar for the NNBD syntax (so any conflicts with the rest of the language would come up), and also that it's possible to experiment with it (tools/spec_parse.py). That grammar is not currently the source of truth for NNBD syntax, but it tracks dart-lang/language#293 closely.

@danrubel
Copy link

The current implementation treats ?. as a single token meaning that

  var foo = bar?.name;  // <--- valid - no space between ? and .
  var foo = bar? .name; // <--- invalid - space between ? and .

Should we do the same for !. so that it's consistent?

@bwilkerson
Copy link
Member

No. The '!' operator is a postfix operator, and doesn't need to be followed by a period:

int x = y!;

The expression x!.y is equivalent to x! . y or even (x!).y.

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.
Projects
None yet
Development

No branches or pull requests

4 participants