sweet-core icon indicating copy to clipboard operation
sweet-core copied to clipboard

Redefinition of a duplicate syntax binding should be an error

Open disnet opened this issue 9 years ago • 5 comments

Currently a duplicate syntax declaration in the same scope will override the previous binding:

syntax m = ctx => #`first`;
syntax m = ctx => #`second`;
m; // second

It should be following let/const binding semantics and throw an early error.

disnet avatar Apr 21 '16 05:04 disnet

Is this the spot?

https://github.com/mozilla/sweet.js/blob/master/src/enforester.js#L1804

gabejohnson avatar May 06 '16 16:05 gabejohnson

nm. Didn't see you had self-assigned

gabejohnson avatar May 06 '16 16:05 gabejohnson

It's actually here: https://github.com/mozilla/sweet.js/blob/master/src/token-expander.js#L23-L34

But its a bit subtle so I need to think through it.

disnet avatar May 06 '16 18:05 disnet

This does throw an error now

Error: Scopeset {outsideEdge_1, insideEdge0_2} has ambiguous subsets {outsideEdge_1, insideEdge0_2}, {outsideEdge_1, insideEdge0_2}

Though it could probably be a little more helpful.

gabejohnson avatar Jan 19 '17 16:01 gabejohnson

Agreed, in general the ambiguous subsets error needs to be more descriptive (say what and where the binding was) and this case in particular the error should mention re-declaration.

disnet avatar Jan 24 '17 19:01 disnet