[JVM IR] Do not generate clinit as enclosing method.

The JVM and newer Android runtimes treats that the same as if
there is no enclosing method. However, older Android runtimes
for Android 5 and 6 throw exceptions on reflective access
and even older runtimes have different behavior. To avoid
those issues, exclude <clinit> from enclosing method attributes.

^ KT-48754 Fixed
This commit is contained in:
Mads Ager
2021-09-30 13:11:31 +02:00
committed by Alexander Udalov
parent 56867d9c7e
commit b61389f6f9
9 changed files with 63 additions and 8 deletions
@@ -446,7 +446,7 @@ class ClassCodegen private constructor(
?: error("Class in a non-static initializer found, but container has no constructors: ${containerClass.render()}")
} else parentFunction
if (enclosingFunction != null || irClass.isAnonymousInnerClass) {
val method = enclosingFunction?.let(context.methodSignatureMapper::mapAsmMethod)
val method = enclosingFunction?.let(context.methodSignatureMapper::mapAsmMethod)?.takeIf { it.name != "<clinit>" }
visitor.visitOuterClass(parentClassCodegen!!.type.internalName, method?.name, method?.descriptor)
}
}