-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cannot use unary method taking 2 operators #13282
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
Does the Puzzler Guy have a Batsignal? |
No but we have a Csignal 😄 |
Maybe it's not an issue about the two expansions (of unary op and assignment) but that the backticked identifier is not kosher.
There have been previous bad interactions with backticked identifiers, with case classes, so probably the spec should specify this problematic space. (The spec says not all backticked identifiers are supported, but doesn't add that not all of them will interoperate with other syntaxy features.) |
According to https://scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html this should not parse in 2.x either. The LHS of an assignment must be an identifier, or a field reference. |
In fact I have no idea by what reasoning this code could be valid. Can some clarify this? |
In such case, it looks like Scala Native was using forbidden syntax for quite a long time! To make some better context here's actual usage in Scala 2 code and original definition of method |
The reasoning is
|
It's worth saying that it's a very clever use of forbidden syntax. I also like that the operator was upgraded from boring When support for I'll take a swing at closing the syntax hole in Scala 2. I may vacillate a bit on whether it should be allowed. But This could open the door for interesting test framework syntax. Never again will I say, "It's just syntax." For unary ops, the specese is "is equivalent to", but for assignment, it is "is interpreted as". |
I'd like to highlight that having a straightforward syntax for pointers is extremely important for Scala Native's interop. It's not just a clever fringe feature that one uses occasionally, but literally the main way to work with pointers. |
Those are some great pointers. |
Note that |
It's not the parser rule, it's the published syntax, which does not allow this case, and never did. But it seems nobody is looking at that. Which is a pity, really. |
I agree that if the decision is made to accept the syntax, the syntax summary must be updated. You can't rely on "is equivalent to" to mean "is syntactically equivalent to". I only looked at the syntax summary after the previous odersky comment, full disclosure. |
Sample interview question at https://contributors.scala-lang.org/t/functional-syntax/5062/38?u=som-snytt
which spoiler alert doesn't parse anywhere. It's like the meme about precedence, "Most people can't get this math problem." |
Hey, I've probably found a bug inside parser. This code would work without problems in Scala 2. It's a blocker for allowing to compile Scala Native with Scala 3. If it's not a bug, but expected behaviour we would need to change our syntax for Scala 3 users.
Compiler version 3.0.1
Minimized code
Output
Expectation
Should not fail, since it works in Scala 2
The text was updated successfully, but these errors were encountered: