Skip to content

Better disambiguation of leading operators #11376

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

Merged
merged 1 commit into from
Feb 14, 2021

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 10, 2021

Classify something as a leading operator only if it is not followed in turn
by an operator. This means that

acc += (i * `i'`)
`i'` += 1

the i' is no longer classified as a leading operator.

@odersky odersky linked an issue Feb 10, 2021 that may be closed by this pull request
@@ -2,8 +2,7 @@
val a = 5
val x = 1

+ //
`a` * 6
Copy link

@catap catap Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

Are you sure that it is related to this issue?

I feel that it introduces another one similar to this: #7031 / #7024

Copy link
Contributor Author

@odersky odersky Feb 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue is interesting. It worked somewhat by accident before. First, if the backticked "`a`" gets changed to "a" this never compiles. We do not skip a newline after a prefix operator, so we have a prefix operator + with nothing that follows it --> error. What happened previously was that the "`a`" was interpreted as a leading infix operator, so the lexical analyzer saw a noun +, followed by an operator "`a`", and did not insert a new line. Then the parser made different sense of it and reclassified + to a prefix operator and "`a`" to its operand. But now we do not interpret "`a`" as a leading operator anymore, so we get an error (as we should).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

I've also plaid a bit this with scala 2 and can't compile it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. I stared at that test while bringing -Xsource:3 into better alignment. Thanks!

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@odersky odersky merged commit 292aaeb into scala:master Feb 14, 2021
@odersky odersky deleted the fix-i11371 branch February 14, 2021 09:31
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't compile while loop with i'
5 participants