diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt index b83a7b831d7..e06ba3c485b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/CollectionStubMethodGenerator.kt @@ -29,13 +29,15 @@ import org.jetbrains.kotlin.platform.JavaToKotlinClassMap import org.jetbrains.kotlin.resolve.NonReportingOverrideStrategy import org.jetbrains.kotlin.resolve.OverrideResolver import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeUniqueAsSequence import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.KotlinTypeChecker -import org.jetbrains.org.objectweb.asm.Opcodes.* +import org.jetbrains.org.objectweb.asm.Opcodes.ACC_PUBLIC +import org.jetbrains.org.objectweb.asm.Opcodes.ACC_SYNTHETIC import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter import java.util.* @@ -52,6 +54,7 @@ class CollectionStubMethodGenerator( private val typeMapper = state.typeMapper fun generate() { + if (descriptor.kind == ClassKind.INTERFACE) return val superCollectionClasses = findRelevantSuperCollectionClasses() if (superCollectionClasses.isEmpty()) return @@ -281,19 +284,15 @@ class CollectionStubMethodGenerator( private fun FunctionDescriptor.signature(): JvmMethodGenericSignature = typeMapper.mapSignatureWithGeneric(this, OwnerKind.IMPLEMENTATION) private fun generateMethodStub(signature: JvmMethodGenericSignature, synthetic: Boolean) { - // TODO: investigate if it makes sense to generate abstract stubs in traits - var access = ACC_PUBLIC - if (descriptor.kind == ClassKind.INTERFACE) access = access or ACC_ABSTRACT - if (synthetic) access = access or ACC_SYNTHETIC + assert(descriptor.kind != ClassKind.INTERFACE) { "No stubs should be generated for interface ${descriptor.fqNameUnsafe}" } + val access = ACC_PUBLIC or (if (synthetic) ACC_SYNTHETIC else 0) val asmMethod = signature.asmMethod val genericSignature = if (synthetic) null else signature.genericsSignature val mv = v.newMethod(JvmDeclarationOrigin.NO_ORIGIN, access, asmMethod.name, asmMethod.descriptor, genericSignature, null) - if (descriptor.kind != ClassKind.INTERFACE) { - mv.visitCode() - AsmUtil.genThrow(InstructionAdapter(mv), "java/lang/UnsupportedOperationException", "Mutating immutable collection") - FunctionCodegen.endVisit(mv, "built-in stub for $signature", null) - } + mv.visitCode() + AsmUtil.genThrow(InstructionAdapter(mv), "java/lang/UnsupportedOperationException", "Mutating immutable collection") + FunctionCodegen.endVisit(mv, "built-in stub for $signature", null) } } diff --git a/compiler/testData/codegen/bytecodeListing/immutableCollection.txt b/compiler/testData/codegen/bytecodeListing/immutableCollection.txt index 7d933fbc3f7..77245a40867 100644 --- a/compiler/testData/codegen/bytecodeListing/immutableCollection.txt +++ b/compiler/testData/codegen/bytecodeListing/immutableCollection.txt @@ -1,15 +1,8 @@ @kotlin.Metadata public interface ImmutableCollection { public abstract @org.jetbrains.annotations.NotNull method add(p0: java.lang.Object): ImmutableCollection - public abstract method add(p0: java.lang.Object): boolean public abstract @org.jetbrains.annotations.NotNull method addAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): ImmutableCollection - public abstract method addAll(p0: java.util.Collection): boolean - public abstract method clear(): void - public abstract method iterator(): java.util.Iterator public abstract @org.jetbrains.annotations.NotNull method remove(p0: java.lang.Object): ImmutableCollection - public abstract method remove(p0: java.lang.Object): boolean - public abstract method removeAll(p0: java.util.Collection): boolean - public abstract method retainAll(p0: java.util.Collection): boolean } @kotlin.Metadata diff --git a/compiler/testData/codegen/bytecodeListing/noCollectionStubMethodsInInterface.kt b/compiler/testData/codegen/bytecodeListing/noCollectionStubMethodsInInterface.kt new file mode 100644 index 00000000000..7f9cea98046 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/noCollectionStubMethodsInInterface.kt @@ -0,0 +1,2 @@ +interface A : Collection +interface B : List diff --git a/compiler/testData/codegen/bytecodeListing/noCollectionStubMethodsInInterface.txt b/compiler/testData/codegen/bytecodeListing/noCollectionStubMethodsInInterface.txt new file mode 100644 index 00000000000..0546f5b7cea --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/noCollectionStubMethodsInInterface.txt @@ -0,0 +1,5 @@ +@kotlin.Metadata +public interface A + +@kotlin.Metadata +public interface B diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index ac184d95cdf..ebbf04a4d5e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -71,6 +71,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { doTest(fileName); } + @TestMetadata("noCollectionStubMethodsInInterface.kt") + public void testNoCollectionStubMethodsInInterface() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/noCollectionStubMethodsInInterface.kt"); + doTest(fileName); + } + @TestMetadata("samAdapterAndInlinedOne.kt") public void testSamAdapterAndInlinedOne() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/samAdapterAndInlinedOne.kt"); diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt index b0b6cc54f30..e4f31d17275 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt @@ -2079,16 +2079,7 @@ public final class kotlin/text/MatchGroup { } public abstract interface class kotlin/text/MatchGroupCollection : java/util/Collection, kotlin/jvm/internal/markers/KMappedMarker { - public abstract synthetic fun add (Ljava/lang/Object;)Z - public abstract fun add (Lkotlin/text/MatchGroup;)Z - public abstract fun addAll (Ljava/util/Collection;)Z - public abstract fun clear ()V public abstract fun get (I)Lkotlin/text/MatchGroup; - public abstract fun iterator ()Ljava/util/Iterator; - public abstract fun remove (Ljava/lang/Object;)Z - public abstract fun remove (Lkotlin/text/MatchGroup;)Z - public abstract fun removeAll (Ljava/util/Collection;)Z - public abstract fun retainAll (Ljava/util/Collection;)Z } public abstract interface class kotlin/text/MatchResult {