-
Notifications
You must be signed in to change notification settings - Fork 276
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
Scalafmt 3.5.2 with scala3 dialect formats code that is not valid Scala 3 #3188
Comments
@valencik i thought we had discussed in the previous issue whether macros can in fact be defined on a new line, to understand if it's a parser vs formatter problem. so, are you confirming that the compiler does not like it? can you check these options, both using scala2 and scala3 compilers, and let me know:
|
I checked and the compiler handles it correctly. did we already bump the scalameta version to the one with the fix? |
Ach, right. This seems to be an error within Scala 3, Scala 2 allows the newline. We might want to not add the newline in this case. |
@valencik if you're no longer interested in this, should we close it? |
Oh, sorry, I'm still interested. This does still current affect munit: scalameta/munit#518 I though @tgodzik had correctly identified the problem though. Currently scalafmt inserts a newline in the scala3 dialect when it shouldn't as Scala 3 does not allow that. |
Yeah, it seems to be a bug in Dotty, where it counts the newline as an opening of a block, which doesn't happen in Scala 2. We need leave it as is in that case. |
@valencik this is what i need |
I checked it myself and the issue is in the Scala 3 compiler, that this is not allowed. Newline that is. |
@tgodzik which of the options above are allowed by the compiler? |
All of them seem to work, so it's ok if no newline is present between |
@valencik @Atry @tgodzik dotty doesn't seem to define This page also doesn't mention it: https://docs.scala-lang.org/scala3/reference/metaprogramming/macros.html is this an undocumented feature of scala3? |
I don't really know, but I did come across this: also note the "TODO remove" |
Related to scalameta/scalameta#2727
We can see the issue happening here: scalameta/munit#518
(I'm really sorry if my previous issue, linked above, didn't have enough details and inevitably caused us to end up here. 😬 )
Configuration (required)
Command-line parameters (required)
When I run scalafmt via CLI like this:
scalafmt -c .scalafmt.conf test.scala
Steps
Given code like this:
Problem
Scalafmt formats code like this:
Note the
macro MacroCompatScala2.clueImpl
on a new line.Once formatted, scala 3.1.2 will not parse this code, yielding:
Expectation
The output format should be able to parsed by Scala 3
The text was updated successfully, but these errors were encountered: