Open ChayimFriedman2 opened 4 years ago
Nice find! It doesn't seem intentional.
I knew it, and I agree it can be miss interpreted because the doc might say it introduce special identifiers, while even the '_' is part of the identifier so it is not 0 length. So AFAIK it is not really a bug, but an ambiguity of the documentation and/or implementation detail.
Oh right, not zero. I was mistaken because of the consumption of the first _
.
Unless there is plan to forbid them, the issue can be closed.
Are you sure this isn't a bug? If this is by design I'll close the issue, but I suspect that only Bob can answer this... @munificent ?
It definitely wasn't intentional. I'll let @ruby0x1 decide if this is a bug or a, uh, bonus feature. Personally, I would lean towards making it an error, but I don't have a strong preference.
About pro and cons of letting, for me the biggest pros is that other language accept those names and it doesn't introduce an arbitrary limitation that need to be checked.
About the cons, it split the name of the variable, which can make it easier to teach maybe?
But my biggest issue about this, and I remember discussing about it with @munificent in some form when it was designed, we talked about a way to distinguish between variables types. @munificent opted for a neat hack that implied selection by pattern matching, but I also exposed the possibility to unary operators. And the issue with what is proposed is that it tries to make '_' and '__' some kind of operator like thing.
I mean, if operator style is the way to go, lets drop '_' and '__' and use a dedicated set of not over-loadable unary operators like '*', '**' or what ever and the limitation proposed will naturally emerge from that decision.
I don't know whether it's a bug, but it seems like one...
The guilt is here:
https://github.com/wren-lang/wren/blob/039150efebdffcfe850813d13892d2619721df2c/src/vm/wren_compiler.c#L1049-L1052
We do not check that there is a letter or digit (or underscore), not here nor in
readName()
:https://github.com/wren-lang/wren/blob/039150efebdffcfe850813d13892d2619721df2c/src/vm/wren_compiler.c#L782-L803
And we're finishing up with an identifier in length 0 😄 Funny.