Skip to content
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

Align leading infix operator with Scala 3 improvements #9567

Merged
merged 6 commits into from May 13, 2021

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Apr 11, 2021

Align "leading infix operator" with Scala 3. The feature is available under -Xsource:3, and a migration warning is available under -Xmigration:2.13.

Improvements include allowing an infix operator on a line by itself, and a better heuristic for whether to take a back-quoted identifier as an infix operator.

Fixes scala/bug#12071

@scala-jenkins scala-jenkins added this to the 2.13.6 milestone Apr 11, 2021
@som-snytt som-snytt force-pushed the issue/12071 branch 2 times, most recently from 1f8dc38 to 6e0e4f1 Compare April 17, 2021 06:17
@som-snytt som-snytt changed the title WIP Issue/12071 Improve leading infix Apr 17, 2021
@som-snytt som-snytt marked this pull request as ready for review April 17, 2021 06:18
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label May 10, 2021
@SethTisue
Copy link
Member

Expected a toplevel definition (or pure expr warning, here)

This doesn't seem like a final error message — was this a reminder to yourself to do some more work on the code, or is it just something we need to find a better wording for?

@som-snytt
Copy link
Contributor Author

@SethTisue that was a Scala 3 test. I tried to keep the code diff close to Dotty, as these are backports.

@SethTisue
Copy link
Member

SethTisue commented May 11, 2021

Fixes scala/bug#12071

This is related to that bug, but it doesn't fix that bug. In that bug, we agreed that the main thing we want fixed is:

scala> def `test-1`: Int = 23; def `test-2`: Int = 42
def test$minus1: Int
def test$minus2: Int

scala> def y = 1 +
     |   `test-2` + `test-1`
         `test-2` + `test-1`
         ^
On line 2: warning: Line starts with an operator that in future
       will be taken as an infix expression continued from the previous line.
       To force the previous interpretation as a separate statement,
       add an explicit `;`, add an empty line, or remove spaces after the operator.

which is just plain wrong.

I guess that's what you meant by:

This does not yet address the "false positive"

You also wrote:

the fix for which is to change the message to "Please enable -Xsource:3".

but that doesn't make sense to me. No warning should be issued, regardless of whether -Xsource:3 is enabled. (Right?)

(Perhaps this PR is mergeable regardless, that's a separate question...)

@som-snytt
Copy link
Contributor Author

Sorry I missed Seth's question. Yes, that's basically what I mean.

About to push rebase and Dale's idea to just skip the warning, modulo -Xmigration. I see the semantics of that setting is: I'm migrating from "2.13.2", so warn me if something changes. Thereafter, if I bump the flag, I won't see the message again, even if I accidentally write code to the wrong (old) syntax. I guess that is OK because we also check that -Xsource:3, so everything is assumed to be intentional.

Copy link
Member

@dwijnand dwijnand left a comment

Choose a reason for hiding this comment

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

Difficult to follow it all, but the test cases and test case diffs look good. Thank you Som for spending the time to re-align our impl with Scala 3's!

@dwijnand dwijnand merged commit a23259f into scala:2.13.x May 13, 2021
@dwijnand
Copy link
Member

Oh, @som-snytt could you tweak the PR description a little with the changes? Seth and I will also do a pass, but it's probably easier for you to describe them.

@som-snytt som-snytt changed the title Improve leading infix Align leading infix operator with Scala 3 improvements May 13, 2021
@som-snytt som-snytt deleted the issue/12071 branch May 13, 2021 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
4 participants