Skip to content

Commit aa1e850

Browse files
committed
Fix method calls on a Java annotation
In the compiler we pretend that Java annotations are classes, but they're really interfaces from the JVM point of view, so we need to treat them as such in the backend when calling a method on them, otherwise we'll emit invalid bytecode. Needed to get tests/run/i2760 to pass after the backend changes in this PR.
1 parent c77e968 commit aa1e850

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

compiler/src/dotty/tools/backend/jvm/BackendInterface.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,11 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
460460
/** Does this symbol actually correspond to an interface that will be emitted?
461461
* In the backend, this should be preferred over `isInterface` because it
462462
* also returns true for the symbols of the fake companion objects we
463-
* create for Java-defined classes.
463+
* create for Java-defined classes as well as for Java annotations
464+
* which we represent as classes.
464465
*/
465466
final def isEmittedInterface: Boolean = isInterface ||
466-
isJavaDefined && isModuleClass && companionClass.isInterface
467+
isJavaDefined && (isAnnotation || isModuleClass && companionClass.isInterface)
467468

468469
// tests
469470
def isClass: Boolean
@@ -509,6 +510,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
509510
def shouldEmitForwarders: Boolean
510511
def isJavaDefaultMethod: Boolean
511512
def isClassConstructor: Boolean
513+
def isAnnotation: Boolean
512514
def isSerializable: Boolean
513515
def isEnum: Boolean
514516

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
702702
def isEnum = sym.is(Flags.Enum)
703703

704704
def isClassConstructor: Boolean = toDenot(sym).isClassConstructor
705+
def isAnnotation: Boolean = toDenot(sym).isAnnotation
705706
def isSerializable: Boolean = toDenot(sym).isSerializable
706707

707708
/**

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,10 @@ object SymDenotations {
787787
*/
788788
def derivesFrom(base: Symbol)(implicit ctx: Context): Boolean = false
789789

790+
/** Is this a Scala or Java annotation ? */
791+
def isAnnotation(implicit ctx: Context): Boolean =
792+
isClass && derivesFrom(defn.AnnotationClass)
793+
790794
/** Is this symbol a class that extends `java.io.Serializable` ? */
791795
def isSerializable(implicit ctx: Context): Boolean =
792796
isClass && derivesFrom(defn.JavaSerializableClass)

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ object Scala3:
123123
def isSyntheticWithIdent(using Context): Boolean =
124124
sym.is(Synthetic) && !sym.isAnonymous && !sym.name.isEmptyNumbered
125125

126-
def isAnnotation(using Context): Boolean =
127-
sym.derivesFrom(defn.AnnotationClass)
128-
129126
// end SymbolOps
130127

131128
object LocalSymbol:

0 commit comments

Comments
 (0)