diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 7a99fb341b9f..802ca48437db 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -166,13 +166,14 @@ class ClassfileParser( for (i <- 0 until in.nextChar) parseMember(method = false) for (i <- 0 until in.nextChar) parseMember(method = true) classInfo = parseAttributes(classRoot.symbol, classInfo) - if (isAnnotation) addAnnotationConstructor(classInfo) classRoot.registerCompanion(moduleRoot.symbol) moduleRoot.registerCompanion(classRoot.symbol) - setClassInfo(classRoot, classInfo, fromScala2 = false) - setClassInfo(moduleRoot, staticInfo, fromScala2 = false) + setClassInfo(classRoot, classInfo, fromScala2 = false, isAnnotation = isAnnotation) + setClassInfo(moduleRoot, staticInfo, fromScala2 = false, isAnnotation = isAnnotation) + + if (isAnnotation) addAnnotationConstructor(classInfo) } else if (result == Some(NoEmbedded)) { for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) { classRoot.owner.asClass.delete(sym) diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index a2dc5c7a0a82..6cb135429f38 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -95,7 +95,7 @@ object Scala2Unpickler { cls.enter(constr, scope) } - def setClassInfo(denot: ClassDenotation, info: Type, fromScala2: Boolean, selfInfo: Type = NoType)(implicit ctx: Context): Unit = { + def setClassInfo(denot: ClassDenotation, info: Type, fromScala2: Boolean, selfInfo: Type = NoType, isAnnotation: Boolean = false)(implicit ctx: Context): Unit = { val cls = denot.classSymbol val (tparams, TempClassInfoType(parents, decls, clazz)) = info match { case TempPolyType(tps, cinfo) => (tps, cinfo) @@ -120,7 +120,8 @@ object Scala2Unpickler { if (tsym.exists) tsym.setFlag(TypeParam) else denot.enter(tparam, decls) } - if (!denot.flagsUNSAFE.isAllOf(JavaModule)) ensureConstructor(denot.symbol.asClass, decls) + if (!denot.flagsUNSAFE.isAllOf(JavaModule) && !isAnnotation) + ensureConstructor(denot.symbol.asClass, decls) val scalacCompanion = denot.classSymbol.scalacLinkedClass diff --git a/tests/pos-java-interop-separate/annotation-with-inner-class-ref/MyJava_1.java b/tests/pos-java-interop-separate/annotation-with-inner-class-ref/MyJava_1.java new file mode 100644 index 000000000000..916297cbc569 --- /dev/null +++ b/tests/pos-java-interop-separate/annotation-with-inner-class-ref/MyJava_1.java @@ -0,0 +1,15 @@ +public @interface MyJava_1 { + + public String value() default "MyJava"; + + public MyClassTypeA typeA(); + + public MyClassTypeB typeB() default @MyClassTypeB; + + public enum MyClassTypeA { + A, B + } + + public @interface MyClassTypeB {} +} + diff --git a/tests/pos-java-interop-separate/annotation-with-inner-class-ref/MyScala_2.scala b/tests/pos-java-interop-separate/annotation-with-inner-class-ref/MyScala_2.scala new file mode 100644 index 000000000000..e0fd84008f39 --- /dev/null +++ b/tests/pos-java-interop-separate/annotation-with-inner-class-ref/MyScala_2.scala @@ -0,0 +1,13 @@ +@MyJava_1("MyScala1", typeA = MyJava_1.MyClassTypeA.B) +object MyScala { + def a(mj: MyJava_1): Unit = { + println("MyJava") + } + + @MyJava_1(typeA = MyJava_1.MyClassTypeA.A) + def b(): Int = 1 + + @MyJava_1(value = "MyScala2", typeA = MyJava_1.MyClassTypeA.B) + def c(): Int = 2 +} +