-
Notifications
You must be signed in to change notification settings - Fork 214
Should we do bottom-up disambiguation of set/map literals with spreads? #167
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
Comments
We knew the rules would have to be generalized for spreads/if/for elements. For something that is syntactically indistinguishable, we should use types to determine the meaning. Then all following steps can use the static type of the expression to see what the choice was. I would first use context type if available. If not, it's a map literal and each sub-part is an entry. For map entries, we'll probably have to talk about "key context type" and "value context type" for the map entries. We'll need a new syntactic category for map entries, because we now have sub-entries in if/for constructs. For a non-empty set-or-map literal and the context type is not available, I'd analyzea the individual element-or-entry expressions, recursively, and give them a vote towards either set or map. For For If there is not at least one vote, or there are votes for both set and map, it's a compile-time error, otherwise pick the one that is voted for. One thing to consider is whether we can make var s = {... {}, ...{1}}; successful, and not fail because |
We decided to do this, specification for how it is done will be forthcoming shortly. |
This is syntactically ambiguous:
It could be a map or set. Right now, the proposal follows the set literal proposal and says the context type can be used to disambiguate:
It makes sense for the set literal proposal to only use the context type to disambiguate empty literals, because it's empty. What else could you use? But it seems weird for spreads:
As it's proposed, this will generate a type error here. There is no context type, so the
{...list}
is inferred as a map literal. Then you get a type error trying to spread a list into a map literal.This feels pretty bad to me. Should we also allow bottom-up inference if there isn't a context type? Would doing so cause any problems I'm not foreseeing? If not, I'm happy to update the proposal.
cc @lrhn @leafpetersen
The text was updated successfully, but these errors were encountered: