Skip to content

Commit 32d3a1b

Browse files
committed
Light classes: generate ACC_STATIC for DefaultImpls classes
To provide consistency between light classes and their delegates IdeLightClass#testExtendingInterfaceWithDefaultImpls still failing since we do not generate implementations delegating to DefaultImpls of superinterfaces
1 parent 5e35106 commit 32d3a1b

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ class InterfaceImplBodyCodegen(
4848
get() = (v as InterfaceImplClassBuilder).isAnythingGenerated
4949

5050
override fun generateDeclaration() {
51+
val codegenFlags = ACC_PUBLIC or ACC_FINAL or ACC_SUPER
52+
val flags = if (state.classBuilderMode == ClassBuilderMode.LIGHT_CLASSES) codegenFlags or ACC_STATIC else codegenFlags
5153
v.defineClass(
52-
myClass.psiOrParent, state.classFileVersion, ACC_PUBLIC or ACC_FINAL or ACC_SUPER,
54+
myClass.psiOrParent, state.classFileVersion, flags,
5355
typeMapper.mapDefaultImpls(descriptor).internalName,
5456
null, "java/lang/Object", ArrayUtil.EMPTY_STRING_ARRAY
5557
)

compiler/testData/asJava/lightClasses/ExtendingInterfaceWithDefaultImpls.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ public interface B extends p.A {
22
@org.jetbrains.annotations.NotNull
33
java.lang.String b();
44

5-
final class DefaultImpls {
5+
static final class DefaultImpls {
66
@org.jetbrains.annotations.NotNull
77
public static java.lang.String b(p.B $this) { /* compiled code */ }
88

99
@org.jetbrains.annotations.NotNull
1010
public static java.lang.String a(p.B $this) { /* compiled code */ }
1111
}
12-
}
12+
}

compiler/testData/asJava/lightClasses/compilationErrors/PrivateInTrait.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
public interface PrivateInTrait {
2-
final class DefaultImpls {
2+
static final class DefaultImpls {
33
private static java.lang.String getNn(PrivateInTrait $this) { /* compiled code */ }
44

55
private static void setNn(PrivateInTrait $this, java.lang.String value) { /* compiled code */ }

compiler/tests-common/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ object LightClassTestCommon {
6464
// Actual text for light class is generated with ClsElementImpl.appendMirrorText() that can find empty DefaultImpl inner class in stubs
6565
// for all interfaces. This inner class can't be used in Java as it generally is not seen from light classes built from Kotlin sources.
6666
// It is also omitted during classes generation in backend so it also absent in light classes built from compiled code.
67-
fun removeEmptyDefaultImpls(text: String) : String = text.replace("\n final class DefaultImpls {\n }\n", "")
67+
fun removeEmptyDefaultImpls(text: String) : String = text.replace("\n static final class DefaultImpls {\n }\n", "")
6868
}

0 commit comments

Comments
 (0)