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

rewrite rules for scala 3 breaks compilation #3337

Closed
mlachkar-da opened this issue Oct 5, 2022 · 12 comments · Fixed by #3343
Closed

rewrite rules for scala 3 breaks compilation #3337

mlachkar-da opened this issue Oct 5, 2022 · 12 comments · Fixed by #3343

Comments

@mlachkar-da
Copy link

mlachkar-da commented Oct 5, 2022

Configuration (required)

Please paste the contents of your .scalafmt.conf file here:

version = 3.5.9

project.git = true

align.preset = none # never align to make the fmt more diff friendly
maxColumn = 100
runner.fatalWarnings = true
trailingCommas = multiple
# Disable scala doc wrapping (behavior changed in v3.0.0).
docstrings.wrap = no
newlines.topLevelStatementBlankLines = [
  { blanks { after = 1 }, regex = "^Import" }
]

rewrite.scala3.convertToNewSyntax = true
runner.dialect = "Scala213Source3"

...

Steps

Given code like this:

  def test(instances: String*): Unit = ()

  val a = test("" +: Seq("").map{_ + ""}: _*)

Problem

Scalafmt formats code like this:

  def test(instances: String*): Unit = ()

  val a = test("" +: Seq("").map{_ + ""}*)

Expectation

I expect the code to compile.

@mlachkar-da
Copy link
Author

this syntax is not yet allowed on scala213source3 dialect.

@tgodzik
Copy link
Contributor

tgodzik commented Oct 5, 2022

That's weird, I thought it's supported based on scala/scala#9584

@tgodzik
Copy link
Contributor

tgodzik commented Oct 5, 2022

It does compile for me 🤔

@mlachkar-da
Copy link
Author

you're right!
let me check which scala version I was using

@mlachkar-da
Copy link
Author

mlachkar-da commented Oct 5, 2022

so it's really a special case:

  val a = test("" +: Seq("").map{_ + ""}: _*)

can you test with that ? it gets rewritte to below, which doesn't compile.

  val a = test("" +: Seq("").map { _ + "" }*)

@tgodzik
Copy link
Contributor

tgodzik commented Oct 5, 2022

Looks like it should get rewritten to val aaa = test(("" +: Seq("").map{_ + ""})*) with the added parenthesis, but looks like a bug in the compiler.

@mlachkar-da
Copy link
Author

I can do a workaround for this, by extracting the value first.

@tgodzik
Copy link
Contributor

tgodzik commented Oct 5, 2022

That might be a good workaround for now, though we should fix it in scalafmt. I think it might have soemthing to do with operator precedence 🤔

@kitbellew
Copy link
Collaborator

scalafmt will not add the parens here, so what's the right solution? not to rewrite this case, keep : _?

@mlachkar-da
Copy link
Author

I think it either needs to add the parenthesis, which I think should be the best solution, or at least do nothing.

@tgodzik
Copy link
Contributor

tgodzik commented Oct 6, 2022

Maybe easiest would be to add parenthesis when infix apply is used?

@kitbellew
Copy link
Collaborator

i don't think we have a way (yet) to add anything. we can remove or replace :) i had some code in the works a long time ago, but didn't finish it...

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 a pull request may close this issue.

3 participants