Skip to content
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

Macro-annotated class with expressions (not defintions) in their body produces compilation error #19539

Closed
pweisenburger opened this issue Jan 26, 2024 · 2 comments · Fixed by #19579
Assignees
Labels
area:metaprogramming:macro-annotations itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@pweisenburger
Copy link
Contributor

Compiler version

3.4.0-RC2
3.4.1-RC1-bin-20240125-453658b-NIGHTLY

Minimized code

import scala.annotation.{experimental, MacroAnnotation}
import scala.quoted.*

@experimental
class annotation extends MacroAnnotation:
  def transform(using Quotes)(tree: quotes.reflect.Definition) = List(tree)
@scala.annotation.experimental
@annotation
class Test:
  println()

Output

The code produces the following compilation error:

[error] -- Error: ~/test/src/main/scala/Test.scala:17:9 
[error] 17 |  println()
[error]    |  ^^^^^^^^^
[error]    |Macro added a definition with the wrong owner - object Predef - class Test in ~/test/src/main/scala/Test.scala
[error] one error found

The macro annotation just returns the input tree without any modification.

The tested class only contains a single println() statement, which triggers the issue. Both Scala 3.3.1 and 3.3.2-RC1 compile without an error. It would be nice if the issue would not make it into 3.4.

Expectation

The code should compile without errors.

The term println indeed has the owner Predef and not Test (as the error message says). Yet, this is expected, not an error.

@pweisenburger pweisenburger added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 26, 2024
@WojciechMazur
Copy link
Contributor

Related to #19537, bisect points to the same commit 038b51e

@WojciechMazur WojciechMazur added regression This worked in a previous version but doesn't anymore area:metaprogramming:macro-annotations and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 26, 2024
@nicolasstucki
Copy link
Contributor

038b51e#diff-2c923586bb8925d78528093e0f6e404948e4c9c0c8417612e513a536141a144dR144

Here we seem to be checking every statement, but we should only check definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:macro-annotations itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants