Skip to content

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

Open
@mrdziuban

Description

@mrdziuban

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions