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
Hi, I am currently rewriting the ExtractAPI phase of dotty to use TASTy Query and I encountered the following exception when implementing apiAnnotation (dotty/tools/dotc/sbt/ExtractAPI.scala:891):
defapiAnnotation(annot: Annotation): api.Annotation= {
// Like with inline defs, the whole body of the annotation and not just its// type is part of its API so we need to store its hash, but Zinc wants us// to extract the annotation type and its arguments, so we use a dummy// annotation argument to store the hash of the tree. We still need to// extract the annotation type in the way Zinc expects because sbt uses this// information to find tests to run (for example junit tests are// annotated @org.junit.Test).
api.Annotation.of(
apiType(annot.tree.tpe), // Used by sbt to find tests to runArray(api.AnnotationArgument.of("TREE_HASH", treeHash(annot.tree, inlineOrigin =NoSymbol).toString)))
}
Here is the stack trace when running through sbt-test/scripted:
tastyquery.Exceptions$MemberNotFoundException: Member <init> not found in TypeRef(PackageRef(java.lang), Deprecated)
at tastyquery.Types$TermRef.doResolve(Types.scala:1076)
at tastyquery.Types$TermRef.computeAndStore$2(Types.scala:1050)
at tastyquery.Types$TermRef.resolved(Types.scala:1051)
at tastyquery.Types$TermRef.underlyingOrMethodic(Types.scala:1085)
at tastyquery.Types$TermType.widenTermRef(Types.scala:456)
at tastyquery.Trees$Apply.computeAndStore$2(Trees.scala:354)
at tastyquery.Trees$Apply.methodType(Trees.scala:357)
at tastyquery.Trees$Apply.instantiateMethodType(Trees.scala:363)
at tastyquery.Trees$Apply.calculateType(Trees.scala:367)
at tastyquery.Trees$TermTree.computeAndStore$1(Trees.scala:98)
at tastyquery.Trees$TermTree.tpe(Trees.scala:99)
at poc$package$.main(poc.scala:32)
at main.main(poc.scala:12)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
Expected behavior
No exception should be thrown when calling tree.tpe. In dotty, annot.tree.tpe returns something similar to TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),trait Deprecated).
Findings
Custom java annotations
The issue also occurs with a custom class annotated with custom java annotations, like
packagecustomannotations;
public @interface CustomAnnotation {
Stringdescription() default"";
}
After some digging, I found that tree.tpe ends up calling fun.tpe.widenTermRef (tastyquery/Trees.scala:354), which ends up calling findMember (tastyquery/Symbols:1476), which returns None if name == nme.Constructor.
Thanks in advance for your help !
The text was updated successfully, but these errors were encountered:
Hi, I am currently rewriting the
ExtractAPI
phase of dotty to use TASTy Query and I encountered the following exception when implementingapiAnnotation
(dotty/tools/dotc/sbt/ExtractAPI.scala:891):Here is the stack trace when running through
sbt-test/scripted
:The issue occurs when invoking
tpe
on the tree of a java annotation.Minimal reproducible example
build.sbt
src/main/scala/poc.scala
Observed behavior
Expected behavior
No exception should be thrown when calling
tree.tpe
. In dotty,annot.tree.tpe
returns something similar toTypeRef(ThisType(TypeRef(NoPrefix,module class lang)),trait Deprecated)
.Findings
Custom java annotations
The issue also occurs with a custom class annotated with custom java annotations, like
The issue does not occur with scala annotations.
Origin
After some digging, I found that
tree.tpe
ends up callingfun.tpe.widenTermRef
(tastyquery/Trees.scala:354), which ends up callingfindMember
(tastyquery/Symbols:1476), which returnsNone
ifname == nme.Constructor
.Thanks in advance for your help !
The text was updated successfully, but these errors were encountered: