You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Dotty generates an implementation for a field defined in a trait, it loses annotation target information when the trait itself is compiled with Scala 2.13.
Source code
This is a minimized example to demonstrate the problem. Originally it is a case in which A is actually Rule annotation from the junit library. Trait provides an implementation of a field containing @org.junit.Rule for junit tests. Impl is a test class consuming Trait.
Junit framework requires @rule definitions to be public, therefore the definition is requested to be placed on the getter.
x/A.java
packagex;
importjava.lang.annotation.ElementType;
importjava.lang.annotation.Retention;
importjava.lang.annotation.RetentionPolicy;
importjava.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface A {
}
Lets say x/Trait.class is located in a library compiled with scala 2.13 and x/Impl.scala consumes the library and compiles the Impl.scala with scala 3.3.1. This produce a wrong x/Impl.class. The annotation ends up on the private field instead of the public getter. Below are resulting classes decompiled with CFR to java:
Originally compiled with scala 2.13, Trait.class decompiles to:
This issue was picked for the Scala Issue Spree of April 30th. @hamzaremmal, @KuceraMartin and @jan-pieter will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.
When Dotty generates an implementation for a field defined in a trait, it loses annotation target information when the trait itself is compiled with Scala 2.13.
Source code
This is a minimized example to demonstrate the problem. Originally it is a case in which A is actually Rule annotation from the junit library. Trait provides an implementation of a field containing @org.junit.Rule for junit tests. Impl is a test class consuming Trait.
Junit framework requires @rule definitions to be public, therefore the definition is requested to be placed on the getter.
x/A.java
x/Trait.scala
x/Impl.scala
Mix of scala 2.13 and 3.3.1
Lets say x/Trait.class is located in a library compiled with scala 2.13 and x/Impl.scala consumes the library and compiles the Impl.scala with scala 3.3.1. This produce a wrong x/Impl.class. The annotation ends up on the private field instead of the public getter. Below are resulting classes decompiled with CFR to java:
Originally compiled with scala 2.13, Trait.class decompiles to:
Originally compiled with scala 3.3, Impl.class decompiles to:
Only scala 2.13
If everything is compiled with just scala 2.13, then the decompiled Impl.class looks like this:
Only scala 3.3
Everything is fine here as well.
The text was updated successfully, but these errors were encountered: