sbt / zinc

Scala incremental compiler library, used by sbt and other build tools
Apache License 2.0
333 stars 118 forks source link

Changing class parameters doesnt recompile dependent code #1334

Open sake92 opened 6 months ago

sake92 commented 6 months ago

steps

problem

Hello still compiles.

expectation

Hello should not compile.

notes

Seems to be scala 3 related. It works with 2.13 for example

Original issue in Metals: https://github.com/scalameta/metals/issues/6112

SethTisue commented 6 months ago

fyi @Gedochao, as the root cause may be in the Dotty repo

sake92 commented 6 months ago

Hmm, I noticed another similar issue..
I moved a class to another folder, even changed the package, and it did not fail compilation.. Really weird

sake92 commented 6 months ago

It's not a Mill issue btw, I've added sbt too, same issue.
What I didn't realize at the time is that the code successfully compiles, but throws NoSuchMethodError !

PS C:\projects\sake\metals-mill-scala3-class-params-repro> mill scalaHelloWorld.run
[36/49] scalaHelloWorld.compile
[info] compiling 1 Scala source to C:\projects\sake\metals-mill-scala3-class-params-repro\out\scalaHelloWorld\compile.dest\classes ...
[info] done compiling
[49/49] scalaHelloWorld.run
Exception in thread "main" java.lang.NoSuchMethodError: 'void example.MyService.<init>(java.lang.String)'
        at example.Hello$.<clinit>(Hello.scala:5)
        at example.Hello.main(Hello.scala)
1 targets failed
scalaHelloWorld.run subprocess failed
eed3si9n commented 6 months ago

@sake92 Would something like the following be an example?

class MyService(str: String, i: Int)

Like Seth suggested, likely this is more to do with the compiler bridge issue, and not specific to the build tools that calls into Zinc like Mill or sbt.

eed3si9n commented 6 months ago
val service = MyService("fssdfs")

My guess is that the new new-less syntax is failing to register dependency relationship to the MyService constructor, so when the constructor changed, Hello object isn't recompiled.

eed3si9n commented 6 months ago

Actually adding new didn't change the behavior:

> hello/run
[info] compiling 1 Scala source to /private/tmp/metals-mill-scala3-class-params-repro/scalaHelloWorld/target/scala-3.3.1/classes ...
[info] running example.Hello
Exception in thread "sbt-bg-threads-13" java.lang.NoSuchMethodError: 'void example.MyService.<init>(java.lang.String)'
    at example.Hello$.<clinit>(Hello.scala:5)
    at example.Hello.main(Hello.scala)
eed3si9n commented 6 months ago

I suggest reporting this to https://github.com/scala/scala3/issues.

sake92 commented 6 months ago

Thanks for checking @eed3si9n .
I'll report to the scala3 repo.