KAPT: Kapt generates illegal stubs for private interface methods
Interface methods that were private got both the `default` and `private` modifiers when using `jvm-default=all` which is not valid. The stub will now just contain `private` in this case. This fixes KT-48013.
This commit is contained in:
committed by
nataliya.valtman
parent
1cc46ab7fa
commit
b02948b5f7
+1
-1
@@ -915,7 +915,7 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
||||
ElementKind.METHOD, packageFqName, visibleAnnotations, method.invisibleAnnotations, descriptor.annotations
|
||||
)
|
||||
|
||||
if (containingClass.isInterface() && !method.isAbstract() && !method.isStatic()) {
|
||||
if (containingClass.isInterface() && !method.isAbstract() && !method.isStatic() && (method.access and Opcodes.ACC_PRIVATE == 0)) {
|
||||
modifiers.flags = modifiers.flags or Flags.DEFAULT
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !JVM_DEFAULT_MODE: all
|
||||
// EXPECTED_ERROR: (kotlin:15:5) modifier private not allowed here
|
||||
|
||||
interface Foo {
|
||||
fun foo() {
|
||||
@@ -10,4 +11,8 @@ interface Foo {
|
||||
}
|
||||
|
||||
fun bar()
|
||||
|
||||
private fun privateMethodWithDefault() {
|
||||
System.out.println("privateMethodWithDefault")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,7 @@ public abstract interface Foo {
|
||||
}
|
||||
|
||||
public abstract void bar();
|
||||
|
||||
private void privateMethodWithDefault() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !JVM_DEFAULT_MODE: all-compatibility
|
||||
// EXPECTED_ERROR: (kotlin:15:5) modifier private not allowed here
|
||||
|
||||
interface Foo {
|
||||
fun foo() {
|
||||
@@ -10,4 +11,8 @@ interface Foo {
|
||||
}
|
||||
|
||||
fun bar()
|
||||
|
||||
private fun privateMethodWithDefault() {
|
||||
System.out.println("privateMethodWithDefault")
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -11,6 +11,9 @@ public abstract interface Foo {
|
||||
|
||||
public abstract void bar();
|
||||
|
||||
private void privateMethodWithDefault() {
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class DefaultImpls {
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !JVM_DEFAULT_MODE: disable
|
||||
// EXPECTED_ERROR: (kotlin:20:5) modifier private not allowed here
|
||||
|
||||
interface Foo {
|
||||
fun foo() {
|
||||
@@ -11,4 +12,13 @@ interface Foo {
|
||||
}
|
||||
|
||||
fun bar()
|
||||
|
||||
private fun privateMethodWithDefault() {
|
||||
System.out.println("privateMethodWithDefault")
|
||||
}
|
||||
|
||||
@JvmDefault
|
||||
private fun privateMethodWithDefault2() {
|
||||
System.out.println("privateMethodWithDefault2")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ public abstract interface Foo {
|
||||
|
||||
public abstract void bar();
|
||||
|
||||
@kotlin.jvm.JvmDefault()
|
||||
private void privateMethodWithDefault2() {
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class DefaultImpls {
|
||||
|
||||
@@ -21,5 +25,8 @@ public abstract interface Foo {
|
||||
public static void foo(@org.jetbrains.annotations.NotNull()
|
||||
Foo $this) {
|
||||
}
|
||||
|
||||
private static void privateMethodWithDefault(Foo $this) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// !JVM_DEFAULT_MODE: enable
|
||||
// EXPECTED_ERROR: (kotlin:20:5) modifier private not allowed here
|
||||
|
||||
interface Foo {
|
||||
fun foo() {
|
||||
@@ -11,4 +12,13 @@ interface Foo {
|
||||
}
|
||||
|
||||
fun bar()
|
||||
|
||||
private fun privateMethodWithDefault() {
|
||||
System.out.println("privateMethodWithDefault")
|
||||
}
|
||||
|
||||
@JvmDefault
|
||||
private fun privateMethodWithDefault2() {
|
||||
System.out.println("privateMethodWithDefault2")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ public abstract interface Foo {
|
||||
|
||||
public abstract void bar();
|
||||
|
||||
@kotlin.jvm.JvmDefault()
|
||||
private void privateMethodWithDefault2() {
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class DefaultImpls {
|
||||
|
||||
@@ -21,5 +25,8 @@ public abstract interface Foo {
|
||||
public static void foo(@org.jetbrains.annotations.NotNull()
|
||||
Foo $this) {
|
||||
}
|
||||
|
||||
private static void privateMethodWithDefault(Foo $this) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user