-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Surprising parsing behaviour for objects ending with _
#16072
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
That's a pretty good warning. Luckily everyone always compiles with
Here, we want to write |
I think the only thing we could do here is to improve the warning/error message. object Hello_: is equivalent to object `Hello_:` and not object `Hello_`: |
It feels like the warning is a warning because we thought that indenting too much is harmless, but here the indentation is evidently misleading. One of the basic reasons we went for indentation-based syntax is to prevent misleading indentation, so I think we should emit an error here. @odersky what do you think about this? |
There are other situations where you might want this. Example:
(this pattern is used a lot in Or:
|
Without a clear idea how this should be improved there's nothing to do. So far I have not seen anything. |
Relatedly, #10671 I tried just checking ahead from objectDef or classDef when Maybe it's worth the effort because "colon fusion" |
I see on my local branch the carets did not line up. (Trailing comments, etc.) On discord, the problem of "accidental fusion of colon" came up again, in the context that it is not only accidental but surprising, the way a banana peel is not surprising when someone slips on it, unless one has no experience with them. Has no one ever proposed allowing (some subset of) trailing colon opchars only for operators, which are encouraged for infix? That sounds draconian. Perhaps a deprecation under |
Ok. So this issue happens because the users end the object's name with an underscore and they accidentally "fuse" the colon. How about we just refuse to compile objects with such names, unless they are quoted? We could emit an error early during the parsing stage. Example of the problematic scenario:
The user wanted to name the object Example of fixed code:
Now it should be clear to the user what the object's name actually is. Thoughts? |
it's not more restrictive than
|
Objects ending with
_
that have a body are parsed in a surprising way.I only narrowed it down accidentally, but the symptoms were lots of compiler errors because of the defs I expected to be in the companion actually being at top level.
Compiler version
3.2.0
Minimized code
You can see how
Hello_:
is defined instead, andx
is treated as a top-level definitionOutput
This parsing warning is the only indication that helped me figure out that something was off:
Expectation
The code either parses correctly, or fails to parse, or gives a meaningful warning
The text was updated successfully, but these errors were encountered: