Should adjacent map literals be a valid map update syntax?

This has tripped me up a couple of times I missed a comma in a long list of maps

1> #{a => b}#{c => d}.
#{a => b,c => d}

I would have expected this to be a syntax error, but it compiles and then troubleshooting takes a lot longer. Is there any good reason for it?

3 Likes

The reason is that any expression is permitted on the left hand side of the map update syntax. It would be more work and less consistent for the compiler to allow any expression except for a map literal.

It can be fun to test out what odd things like this you can get a language parser to accept, they’re typically a lot more lenient than you might expect.

7 Likes

I guess it is a valid map you could also do.

Map = #{a => b}.
Map#{c => d}.

But yes it have bitten me too.

4 Likes

For reference, I once wrote an article about that…

7 Likes

Something good to add to a linter though?

5 Likes

and now that we’re at it…

…and we’re always happy to review and merge PRs for new rules :slight_smile:

2 Likes

Ahh, that’s an old still open issue…

1 Like