Skip to content

Commit c42428d

Browse files
committed
Fix superclass for Java interface symbols created in JavaMirrors
According to the spec [1] the superclass of an interface is always Object. Restores the tests that were moved to pending in bf951ec, fixex part of SI-9374. [1] https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.1
1 parent 743b729 commit c42428d

17 files changed

+2
-1
lines changed

src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ abstract class ClassfileParser {
284284

285285
def getType(index: Int): Type = getType(null, index)
286286
def getType(sym: Symbol, index: Int): Type = sigToType(sym, getExternalName(index))
287-
def getSuperClass(index: Int): Symbol = if (index == 0) AnyClass else getClassSymbol(index)
287+
def getSuperClass(index: Int): Symbol = if (index == 0) AnyClass else getClassSymbol(index) // the only classfile that is allowed to have `0` in the super_class is java/lang/Object (see jvm spec)
288288

289289
private def createConstant(index: Int): Constant = {
290290
val start = starts(index)

src/reflect/scala/reflect/runtime/JavaMirrors.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ private[scala] trait JavaMirrors extends internal.SymbolTable with api.JavaUnive
755755
val ifaces = jclazz.getGenericInterfaces.toList map typeToScala
756756
val isAnnotation = JavaAccFlags(jclazz).isAnnotation
757757
if (isAnnotation) AnnotationClass.tpe :: ClassfileAnnotationClass.tpe :: ifaces
758+
else if (jclazz.isInterface) ObjectTpe :: ifaces // interfaces have Object as superclass in the classfile (see jvm spec), but getGenericSuperclass seems to return null
758759
else (if (jsuperclazz == null) AnyTpe else typeToScala(jsuperclazz)) :: ifaces
759760
} finally {
760761
parentsLevel -= 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)