Closed valencik closed 2 years ago
@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:
implicit def generate[T](value: T): Clue[T] = macro MacroCompatScala2.clueImpl
implicit def generate[T](value: T): Clue[T] = macro
MacroCompatScala2.clueImpl
implicit def generate[T](
value: T
): Clue[T] = macro MacroCompatScala2.clueImpl
implicit def generate[T](value: T)
: Clue[T] = macro MacroCompatScala2.clueImpl
@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?
@tgodzik for the formatter, #3187
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: https://github.com/scalameta/munit/pull/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 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:
implicit def generate[T](value: T): Clue[T] = macro MacroCompatScala2.clueImpl implicit def generate[T](value: T): Clue[T] = macro MacroCompatScala2.clueImpl implicit def generate[T]( value: T ): Clue[T] = macro MacroCompatScala2.clueImpl implicit def generate[T](value: T) : Clue[T] = macro MacroCompatScala2.clueImpl
@valencik this is what i need
can you check these options, both using scala2 and scala3 compilers, and let me know:
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 =
and the macro keyword
@valencik @atry @tgodzik dotty doesn't seem to define macro
as a valid keyword: https://dotty.epfl.ch/docs/internals/syntax.html
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 https://github.com/scalameta/scalameta/issues/2727
We can see the issue happening here: https://github.com/scalameta/munit/pull/518
(I'm really sorry if my previous issue, linked above, didn't have enough details and inevitably caused us to end up here. :grimacing: )
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