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

Are nullable types allowed as type literals? #278

Closed
leafpetersen opened this issue Mar 19, 2019 · 3 comments
Closed

Are nullable types allowed as type literals? #278

leafpetersen opened this issue Mar 19, 2019 · 3 comments
Labels
nnbd NNBD related issues

Comments

@leafpetersen
Copy link
Member

Is the following a syntactically valid post-nnbd program?

void main() {
  print(int?);
  var x = int?;
  var y = {int? -3 : 4};
}

cc @lrhn @munificent @eernstg

@leafpetersen leafpetersen added the nnbd NNBD related issues label Mar 19, 2019
@eernstg
Copy link
Member

eernstg commented Mar 20, 2019

I think we have a similar amount of freedom here as we do with identifier<type,arguments> for literals denoting parameterized types (and, coincidentally, generic function instantiations): We can add support for that kind of syntax, and it makes no difference for anything other than the syntax (because the underlying runtime support needs to exist anyway). This would presumably allow us to make that decision independently (no need to hurry).

We would have stuff like {x == int?? 2 : 3} which could be a set (containing 2 if x is int? and otherwise 3) or a map (namely {b: 3} where b is true or false (or 2 if == can return null)), so there's certainly a potential for ambiguities.

@munificent
Copy link
Member

In general, yes, I think it would be nice to support all type annotations as type literals. In ambiguous cases, can we simply always prefer the non-type literal interpretation and then if you want the type literal, you parenthesize it?

We would have stuff like {x == int?? 2 : 3}

I think that one is easy because we can and should always lex ?? a single token without doing the magic "split in two only if needed" that we do for >>.

@leafpetersen
Copy link
Member Author

Closing this in favor of the existing issue on type expressions. We won't land this as part of NNBD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nnbd NNBD related issues
Projects
None yet
Development

No branches or pull requests

3 participants