diff --git a/compiler/testData/diagnostics/tests/regressions/kt7804.kt b/compiler/testData/diagnostics/tests/regressions/kt7804.kt new file mode 100644 index 00000000000..4f2a17dfefb --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt7804.kt @@ -0,0 +1,64 @@ +// See also KT-7804 (Wrong type inference of kotlin.Any? was for 'a' without explicit type) +fun foo(a: T) = a + +class A + +fun test(v: T): T { + val a = if (v !is A) { + foo(v) as T + } + else { + v + } + + val t: T = a + return t +} + +fun test2(v: T): T { + val a = if (v !is A) { + foo(v) as T + } + else { + v as T + } + + val t: T = a + return t +} + +fun test3(v: T): T { + val a = if (v !is A) { + foo(v) + } + else { + v + } + + val t: T = a + return t +} + +fun test4(v: T): T { + val a: T = if (v !is A) { + foo(v) as T + } + else { + v + } + + val t: T = a + return t +} + +fun test5(v: T): T { + val a: T = if (v !is A) { + foo(v) + } + else { + v + } + + val t: T = a + return t +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt7804.txt b/compiler/testData/diagnostics/tests/regressions/kt7804.txt new file mode 100644 index 00000000000..036c760d4ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt7804.txt @@ -0,0 +1,15 @@ +package + +public fun foo(/*0*/ a: T): T +public fun test(/*0*/ v: T): T +public fun test2(/*0*/ v: T): T +public fun test3(/*0*/ v: T): T +public fun test4(/*0*/ v: T): T +public fun test5(/*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 3ab54a0f3b6..dfb828aacbd 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -13899,6 +13899,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt7804.kt") + public void testKt7804() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt7804.kt"); + doTest(fileName); + } + @TestMetadata("kt847.kt") public void testKt847() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt847.kt");