Skip to content

Should we do bottom-up disambiguation of set/map literals with spreads? #167

Closed
@munificent

Description

@munificent

This is syntactically ambiguous:

{...a}

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:

Set s = {...a}; // Set
Map m = {...}; // Map

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:

var list = [1, 2, 3];
var set = {...list};

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions