Skip to content

Incremental compilation doesn't invalidate sources that use macro annotation when annotation's transform method changes #22999

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

Open
mrdziuban opened this issue Apr 14, 2025 · 1 comment

Comments

@mrdziuban
Copy link

mrdziuban commented Apr 14, 2025

Compiler version

3.6.4 and latest nightly 3.7.1-RC1-bin-20250413-5b4b5c2-NIGHTLY

Minimized code

https://github.com/mrdziuban/scala3-macro-annotation-incremental-compilation

// Annotation.scala
package example

import scala.quoted.*

final class annot extends annotation.MacroAnnotation {
  def transform(using q: Quotes)(
    definition: q.reflect.Definition,
    companion: Option[q.reflect.Definition],
  ): List[q.reflect.Definition] = {
    println("*** transform")
    List(definition)
  }
}

// Test.scala
package example

@annot object Test

After changing the body of def transform, Test.scala is not recompiled.

This is obviously a very simple example, but I've been able to reproduce the same issue with more complex code where I'm changing how the definition is transformed.

Output

On first compile:

[info] compiling 2 Scala sources to /Users/matt/scala3-macro-annotation-incremental-compilation/target/scala-3.6.4/classes ...
*** transform
[info] done compiling
[success] Total time: 0 s, completed Apr 14, 2025, 4:13:02 PM

On second compile, after changing the println:

[info] compiling 1 Scala source to /Users/matt/scala3-macro-annotation-incremental-compilation/target/scala-3.6.4/classes ...
[info] done compiling
[success] Total time: 0 s, completed Apr 14, 2025, 4:13:07 PM

Expectation

Test.scala should be recompiled since it may now be transformed differently by annot.

@mrdziuban mrdziuban added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 14, 2025
@Gedochao
Copy link
Contributor

This is curious...
I can reproduce it with SBT as well as the raw scalac command... but not with Scala CLI 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants