Skip to content

Wrong rewrite of a partial function passed to a symbolic operator #20002

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

Closed
OndrejSpanel opened this issue Mar 22, 2024 · 3 comments · Fixed by #20043
Closed

Wrong rewrite of a partial function passed to a symbolic operator #20002

OndrejSpanel opened this issue Mar 22, 2024 · 3 comments · Fixed by #20043

Comments

@OndrejSpanel
Copy link
Member

Compiler version

3..4.1-RC2

Minimized code

Use -indent -rewrite on following code:

@main
def main: Unit = {

  object reactions {
    def += (f: PartialFunction[String, Unit]) = ???
  }

  reactions += {
    case a =>
    case b =>
  }
}

Output

@main
def main: Unit =

  object reactions:
    def += (f: PartialFunction[String, Unit]) = ???

  reactions += :
    case a =>
    case b =>

Compiling this results in following error:

C:\Dev\Sandbox\src\main\scala\Main.scala:7:16
expression expected but : found
reactions += :

Expectation

The output of "-indent", "-rewrite" should compile without errors

Note

This pattern is common when using Scala Swing.

@OndrejSpanel OndrejSpanel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 22, 2024
@OndrejSpanel
Copy link
Member Author

A similar pattern is also often seen in parser / combinators, where partial function follows ^^.

@LucySMartin
Copy link

I'm having a look at this. No promises, very new to this stuff, but I've reproduced and found a good looking spot to try some changes.

@LucySMartin
Copy link

I've raised #20043 - I think it fixes this

@Gedochao Gedochao added area:rewriting tool and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 28, 2024
sjrd added a commit that referenced this issue Apr 11, 2024
…fix expression. (#20043)

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
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants