-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Rewrite compiler flag on some generated code can break it #17456
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
Comments
Alright so I ended up just moving this from the discussion into an issue since in reality it does produce broken code and this could bit uses if they try this out. In general I just don't think we should try to rewrite this, but I'm also not 100% sure how to avoid this. I'm not sure if there is some tag on a source when it's passed to the compiler indicating that it was generated or something, but if so we could detect that and not try to rewrite it I guess. I'm open for any idea/suggestions others might have here. There's also the idea that in reality, this is valid code, so in reality rewriting should be able to work here. |
Alright, you can minimize this down to: //> using scala 3.3.1-RC1-bin-20230510-d6c643c-NIGHTLY
//> using options -rewrite -indent
object example {
def foo(a: Any) = ???
def appply() = foo {
Seq(1, 2, 3)
}
} Running //> using scala 3.3.1-RC1-bin-20230510-d6c643c-NIGHTLY
//> using options -rewrite -indent
object example:
def foo(a: Any) = ???
def appply() = foo:
Seq(1, 2, 3) Which has broken indentation for the |
In general it seems the compiler does not try to fix the indentation at all. def f = {
val x = ""
x
} is rewritten into: def f =
val x = ""
x I also found a few related/unrelated bugs/features:
class A {
def foo = ""
}
class B {
def bar = ""
} // no \n here is rewritten to class A:
def foo = ""
class B {
def bar = ""
}
class B {
} |
Discussed in #17453
Originally posted by PeuTit May 10, 2023
Creating a new Play application with g8 and the play-scala-seed.g8 template.
I was testing the rewrite capabilities of the compiler with the following options:
Launching a sbt shell & compiling the project, I'm facing the following errors:
Does anyone have ever faced this issue previously?
minimal example
Actually, I was able to reproduce this. Interesting one. So what happens is that on the first compile it will take the Scala code that gets generated from the
index.scala.html
and attempt to rewrite it. It does this, but outputs invalid code. For example here is what yourindex.scala.html
really looks like when passed to the compiler:This then gets rewritten to
Which has a whole handful of problems. The thing is, is that I don't even think we should be trying to rewrite these files, but I don't know if there is a good way to filter them out since Dotty I believe is just going to try and rewrite everything, whether it's generated code or not.
The text was updated successfully, but these errors were encountered: