From d2c372a4f7a3b491abb0cff968ba7d8a9f3156c7 Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Wed, 15 May 2019 15:33:08 +0200 Subject: [PATCH] JVM_IR: No EnclosingMethod attribute for member classes. The comment in the code is correct that EnclosingMethod attributes should only be generated for local and anonymous classes. We were generating them for member classes as well which leads to invalid class files. With this change I had to mute one more tests. That is because we lose the parent method and therefore we see a class as a member class instead of a local class. With the old descriptor based check that test still passes. --- .../org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt | 2 +- .../box/reflection/enclosing/localClassInTopLevelFunction.kt | 1 + compiler/testData/compileJavaAgainstKotlin/class/ClassObject.kt | 1 - compiler/testData/compileJavaAgainstKotlin/method/TraitImpl.kt | 1 - 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt index 59e657e025c..9b4f7f717e7 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt @@ -319,7 +319,7 @@ open class ClassCodegen protected constructor( if (containingDeclaration is IrFunction) { val method = typeMapper.mapAsmMethod(containingDeclaration) visitor.visitOuterClass(outerClassName, method.name, method.descriptor) - } else { + } else if (isAnonymous) { visitor.visitOuterClass(outerClassName, null, null) } } diff --git a/compiler/testData/codegen/box/reflection/enclosing/localClassInTopLevelFunction.kt b/compiler/testData/codegen/box/reflection/enclosing/localClassInTopLevelFunction.kt index 4356824e685..5822be741fa 100644 --- a/compiler/testData/codegen/box/reflection/enclosing/localClassInTopLevelFunction.kt +++ b/compiler/testData/codegen/box/reflection/enclosing/localClassInTopLevelFunction.kt @@ -1,3 +1,4 @@ +// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_REFLECT diff --git a/compiler/testData/compileJavaAgainstKotlin/class/ClassObject.kt b/compiler/testData/compileJavaAgainstKotlin/class/ClassObject.kt index 0d6de0f25c5..87d09913465 100644 --- a/compiler/testData/compileJavaAgainstKotlin/class/ClassObject.kt +++ b/compiler/testData/compileJavaAgainstKotlin/class/ClassObject.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR package test class WithClassObject { diff --git a/compiler/testData/compileJavaAgainstKotlin/method/TraitImpl.kt b/compiler/testData/compileJavaAgainstKotlin/method/TraitImpl.kt index ab573da32fb..14d5affe430 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/TraitImpl.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/TraitImpl.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR package test interface Trait {