diff --git a/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype.kt b/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype.kt new file mode 100644 index 00000000000..70a5dceba63 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype.kt @@ -0,0 +1,20 @@ +interface X +interface Z + +interface A : X, Z +interface B : X, Z + +fun interface IFoo where T : X, T : Z { + fun accept(t: T) +} + +fun sel(x: T, y: T) = x + +class G where T: X, T: Z { + fun check(x: IFoo) {} +} + +fun test() { + val g = sel(G(), G()) // g: G + g.check {} // (*) target SAM type: IFoo<{ X & Z }> (TODO: report a compile time error for this case) +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype.txt b/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype.txt new file mode 100644 index 00000000000..bfd58ea000b --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype.txt @@ -0,0 +1,52 @@ +@kotlin.Metadata +public interface A { + // source: 'nonApproxToValidSupertype.kt' +} + +@kotlin.Metadata +public interface B { + // source: 'nonApproxToValidSupertype.kt' +} + +@kotlin.Metadata +public final class G { + // source: 'nonApproxToValidSupertype.kt' + public method (): void + public final method check(@org.jetbrains.annotations.NotNull p0: IFoo): void +} + +@kotlin.Metadata +public interface IFoo { + // source: 'nonApproxToValidSupertype.kt' + public abstract method accept(@org.jetbrains.annotations.NotNull p0: X): void +} + +@kotlin.Metadata +final class NonApproxToValidSupertypeKt$test$1 { + // source: 'nonApproxToValidSupertype.kt' + enclosing method NonApproxToValidSupertypeKt.test()V + public final static field INSTANCE: NonApproxToValidSupertypeKt$test$1 + inner (anonymous) class NonApproxToValidSupertypeKt$test$1 + static method (): void + method (): void + public final method accept(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void + public synthetic bridge method accept(p0: X): void +} + +@kotlin.Metadata +public final class NonApproxToValidSupertypeKt { + // source: 'nonApproxToValidSupertype.kt' + inner (anonymous) class NonApproxToValidSupertypeKt$test$1 + public final static method sel(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object + public final static method test(): void +} + +@kotlin.Metadata +public interface X { + // source: 'nonApproxToValidSupertype.kt' +} + +@kotlin.Metadata +public interface Z { + // source: 'nonApproxToValidSupertype.kt' +} diff --git a/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype2.kt b/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype2.kt new file mode 100644 index 00000000000..def8396ddb1 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype2.kt @@ -0,0 +1,23 @@ +interface X: U, W +interface Z: U, W + +interface U +interface W + +interface A : X, Z +interface B : X, Z + +fun interface IFoo where T : U, T : W { + fun accept(t: T) +} + +fun sel(x: T, y: T) = x + +class G where T: U, T: W { + fun check(x: IFoo) {} +} + +fun test() { + val g = sel(G(), G()) + g.check {} // TODO: report a compile time error for this case +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype2.txt b/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype2.txt new file mode 100644 index 00000000000..e5652e7518d --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype2.txt @@ -0,0 +1,62 @@ +@kotlin.Metadata +public interface A { + // source: 'nonApproxToValidSupertype2.kt' +} + +@kotlin.Metadata +public interface B { + // source: 'nonApproxToValidSupertype2.kt' +} + +@kotlin.Metadata +public final class G { + // source: 'nonApproxToValidSupertype2.kt' + public method (): void + public final method check(@org.jetbrains.annotations.NotNull p0: IFoo): void +} + +@kotlin.Metadata +public interface IFoo { + // source: 'nonApproxToValidSupertype2.kt' + public abstract method accept(@org.jetbrains.annotations.NotNull p0: U): void +} + +@kotlin.Metadata +final class NonApproxToValidSupertype2Kt$test$1 { + // source: 'nonApproxToValidSupertype2.kt' + enclosing method NonApproxToValidSupertype2Kt.test()V + public final static field INSTANCE: NonApproxToValidSupertype2Kt$test$1 + inner (anonymous) class NonApproxToValidSupertype2Kt$test$1 + static method (): void + method (): void + public final method accept(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void + public synthetic bridge method accept(p0: U): void +} + +@kotlin.Metadata +public final class NonApproxToValidSupertype2Kt { + // source: 'nonApproxToValidSupertype2.kt' + inner (anonymous) class NonApproxToValidSupertype2Kt$test$1 + public final static method sel(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object + public final static method test(): void +} + +@kotlin.Metadata +public interface U { + // source: 'nonApproxToValidSupertype2.kt' +} + +@kotlin.Metadata +public interface W { + // source: 'nonApproxToValidSupertype2.kt' +} + +@kotlin.Metadata +public interface X { + // source: 'nonApproxToValidSupertype2.kt' +} + +@kotlin.Metadata +public interface Z { + // source: 'nonApproxToValidSupertype2.kt' +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java index 8581468d367..018dc25d1b6 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java @@ -2018,6 +2018,18 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/sam/lambdaSpecializedSamInterface.kt"); } + @Test + @TestMetadata("nonApproxToValidSupertype.kt") + public void testNonApproxToValidSupertype() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype.kt"); + } + + @Test + @TestMetadata("nonApproxToValidSupertype2.kt") + public void testNonApproxToValidSupertype2() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype2.kt"); + } + @Test @TestMetadata("reusedSamWrapperClasses.kt") public void testReusedSamWrapperClasses() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java index 10f6a8240c0..9e3ba33ab51 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java @@ -2018,6 +2018,18 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/sam/lambdaSpecializedSamInterface.kt"); } + @Test + @TestMetadata("nonApproxToValidSupertype.kt") + public void testNonApproxToValidSupertype() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype.kt"); + } + + @Test + @TestMetadata("nonApproxToValidSupertype2.kt") + public void testNonApproxToValidSupertype2() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/sam/nonApproxToValidSupertype2.kt"); + } + @Test @TestMetadata("reusedSamWrapperClasses.kt") public void testReusedSamWrapperClasses() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java index ab81c670165..081b73f4a69 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java @@ -1986,6 +1986,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase { runTest("compiler/testData/ir/irText/types/intersectionType3_OI.kt"); } + @TestMetadata("intersectionTypeInSamType.kt") + public void testIntersectionTypeInSamType() throws Exception { + runTest("compiler/testData/ir/irText/types/intersectionTypeInSamType.kt"); + } + @TestMetadata("kt36143.kt") public void testKt36143() throws Exception { runTest("compiler/testData/ir/irText/types/kt36143.kt");