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

Extra check to avoid converting block expressions on the rhs of an in… #20043

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

LucySMartin
Copy link

@LucySMartin LucySMartin commented Mar 28, 2024

…fix expression.

Tests added for:

  • Original cast as per the ticket should not be changed
  • Similar match statement that should update
  • Code blocks in this position, as opposed to a partial function, cant update here
  • Simple change that should apply but in a code position where the op stack is nonempty
  • Equivalent code, but passing in the partial function as a single parameter, again, not updating

Fixes #20002

@som-snytt
Copy link
Contributor

Does the fixes link need to be in the OP comment? I don't see the ticket saying may be fixed by.

Copy link
Member

@hamzaremmal hamzaremmal left a comment

Choose a reason for hiding this comment

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

Thank you for your collaboration to Scala 3. The main issue of this ticket is that at the moment, we rewrite when we have braces after a symbolic operator. The syntax doesn't allow us to have an indented block in this case. For this PR, I would expect at least the following test to work:

  • No rewrite:
Reactions += {
  partialFunction
}
  • Should rewrite (because the operator is not symbolic):
infix def run(f: PartialFunction[Int, Unit]) = ???
    
Reactions run {
  case 0 => ???
}

compiler/src/dotty/tools/dotc/parsing/Parsers.scala Outdated Show resolved Hide resolved
@LucySMartin
Copy link
Author

LucySMartin commented Apr 2, 2024

Thank you for your collaboration to Scala 3. The main issue of this ticket is that at the moment, we rewrite when we have braces after a symbolic operator. The syntax doesn't allow us to have an indented block in this case. For this PR, I would expect at least the following test to work:

  • No rewrite:
Reactions += {
  partialFunction
}
  • Should rewrite (because the operator is not symbolic):
infix def run(f: PartialFunction[Int, Unit]) = ???
    
Reactions run {
  case 0 => ???
}

Oh!
Yep - thats a thing.
My professional roll we use brackets everywhere, thats not a place I knew you could ignore them.
Ill look into that in some more detail this evening.

Copy link
Member

@hamzaremmal hamzaremmal left a comment

Choose a reason for hiding this comment

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

LGTM

@hamzaremmal
Copy link
Member

@LucySMartin Can you squash your commits before I merge it ? Thanks

…bolic infix expression.

Tests added for:
* Original cast as per the ticket should not be changed
* Similar match statement that should update
* Code blocks in this position, as opposed to a partial function, cant update here
* Simple change that should apply but in a code position where the op stack is nonempty
* Equivalent code, but passing in the partial function as a single parameter, again, not updating
@LucySMartin
Copy link
Author

@hamzaremmal Squashed. Do you also want a rebase or no?

@sjrd
Copy link
Member

sjrd commented Apr 11, 2024

Rebasing is not necessary unless there are conflicts.

@sjrd sjrd enabled auto-merge April 11, 2024 07:36
@hamzaremmal
Copy link
Member

@hamzaremmal Squashed. Do you also want a rebase or no?

As @sjrd mentioned, there is no need.

@sjrd sjrd merged commit 2427f56 into scala:main Apr 11, 2024
18 checks passed
@LucySMartin LucySMartin deleted the i20002-rewrite-infix-blocks branch April 11, 2024 15:19
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
WojciechMazur added a commit that referenced this pull request Jul 5, 2024
…s of an in…" to LTS (#21058)

Backports #20043 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
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.

Wrong rewrite of a partial function passed to a symbolic operator
5 participants