diff --git a/compiler/testData/codegen/box/smartCasts/genericIntersection.kt b/compiler/testData/codegen/box/smartCasts/genericIntersection.kt new file mode 100644 index 00000000000..51c34682f0e --- /dev/null +++ b/compiler/testData/codegen/box/smartCasts/genericIntersection.kt @@ -0,0 +1,9 @@ +// See also KT-7801 +class A + +fun test(v: T): T { + val a: T = if (v !is A) v else v + return a +} + +fun box() = test("OK") diff --git a/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.kt b/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.kt new file mode 100644 index 00000000000..9dae20755e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.kt @@ -0,0 +1,7 @@ +// See also KT-7801 +class A + +fun test(v: T): T { + val a: T = if (v !is A) v else v + return a +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.txt b/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.txt new file mode 100644 index 00000000000..b1cede95de3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/genericIntersection.txt @@ -0,0 +1,10 @@ +package + +public fun test(/*0*/ v: T): T + +public final class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index ac03b8865e9..d49b1a4d1a3 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -15615,6 +15615,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("genericIntersection.kt") + public void testGenericIntersection() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/genericIntersection.kt"); + doTest(fileName); + } + @TestMetadata("genericSet.kt") public void testGenericSet() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/genericSet.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index fc227d48ece..d25f0b1c34d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -7357,6 +7357,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("genericIntersection.kt") + public void testGenericIntersection() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/smartCasts/genericIntersection.kt"); + doTest(fileName); + } + @TestMetadata("genericSet.kt") public void testGenericSet() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/smartCasts/genericSet.kt");