Skip to content

Fix #9492: Avoid forcing nested annotation #9536

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

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,6 @@ object Annotations {
protected var myTree: Tree | (Context ?=> Tree) = (using ctx) => treeFn(using ctx)
}

def deferred(atp: Type, args: List[Tree])(using Context): Annotation =
deferred(atp.classSymbol)(New(atp, args))

def deferredResolve(atp: Type, args: List[ast.untpd.Tree])(using Context): Annotation =
deferred(atp.classSymbol)(ast.untpd.resolveConstructor(atp, args))

/** Extractor for child annotations */
object Child {

Expand Down
17 changes: 14 additions & 3 deletions compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,25 @@ class ClassfileParser(
Some(untpd.JavaSeqLiteral(elems, TypeTree()))
}
case ANNOTATION_TAG =>
parseAnnotation(index, skip) map (_.tree)
parseAnnotation(index, skip).map(_.untpdTree)
}
}

class ClassfileAnnotation(annotType: Type, args: List[untpd.Tree]) extends LazyAnnotation {
protected var mySym: Symbol | (Context ?=> Symbol) =
(using ctx: Context) => annotType.classSymbol

protected var myTree: Tree | (Context ?=> Tree) =
(using ctx: Context) => untpd.resolveConstructor(annotType, args)

def untpdTree(using Context): untpd.Tree =
untpd.New(untpd.TypeTree(annotType), List(args))
}

/** Parse and return a single annotation. If it is malformed,
* return None.
*/
def parseAnnotation(attrNameIndex: Char, skip: Boolean = false)(using Context): Option[Annotation] = try {
def parseAnnotation(attrNameIndex: Char, skip: Boolean = false)(using Context): Option[ClassfileAnnotation] = try {
val attrType = pool.getType(attrNameIndex)
attrType match
case tp: TypeRef =>
Expand All @@ -584,7 +595,7 @@ class ClassfileParser(
}
}
if (hasError || skip) None
else Some(Annotation.deferredResolve(attrType, argbuf.toList))
else Some(ClassfileAnnotation(attrType, argbuf.toList))
}
catch {
case f: FatalError => throw f // don't eat fatal errors, they mean a class was not found
Expand Down
15 changes: 15 additions & 0 deletions tests/pos-java-interop-separate/i9492/A_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import java.lang.annotation.*;

@interface BaseClassAnn {
Type[] value();
@interface Type {
Class<?> value();
}
}

@BaseClassAnn({
@BaseClassAnn.Type(value=A_1.class)
})
abstract class BaseClass {}

public class A_1 extends BaseClass {}
3 changes: 3 additions & 0 deletions tests/pos-java-interop-separate/i9492/B_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
def oops: A_1 = ???
}