diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10444.kt b/compiler/testData/diagnostics/tests/smartCasts/kt10444.kt new file mode 100644 index 00000000000..4a7dcb0e5b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10444.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// KT-10444 Do not ignore smart (unchecked) casts to the same classifier + +class Qwe(val a: T?) { + fun test1(obj: Any) { + obj as Qwe + check(obj.a) + } + + fun test1(obj: Qwe<*>) { + obj as Qwe + check(obj.a) + } + + fun check(a: T?) { + } +} + +open class Foo +open class Bar(open val a: T?, open val b: T?) { + @Suppress("UNCHECKED_CAST") + fun compare(obj: Any) { + if (obj !is Bar<*>) { + throw IllegalArgumentException() + } + if (System.currentTimeMillis() > 100) { + val b = (obj as Bar).b + if (b == null) throw IllegalArgumentException() + check(obj.a, b) + } + } + fun check(a: T?, b: T) { + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10444.txt b/compiler/testData/diagnostics/tests/smartCasts/kt10444.txt new file mode 100644 index 00000000000..38ce0c968ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10444.txt @@ -0,0 +1,30 @@ +package + +public open class Bar { + public constructor Bar(/*0*/ a: T?, /*1*/ b: T?) + public open val a: T? + public open val b: T? + public final fun check(/*0*/ a: T?, /*1*/ b: T): kotlin.Unit + @kotlin.Suppress(names = {"UNCHECKED_CAST"}) public final fun compare(/*0*/ obj: kotlin.Any): kotlin.Unit + 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 +} + +public open class Foo { + public constructor Foo() + 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 +} + +public final class Qwe { + public constructor Qwe(/*0*/ a: T?) + public final val a: T? + public final fun check(/*0*/ a: T?): kotlin.Unit + 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 final fun test1(/*0*/ obj: Qwe<*>): kotlin.Unit + public final fun test1(/*0*/ obj: kotlin.Any): kotlin.Unit + 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 f746717f17f..68fc8ba4e7a 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -15567,6 +15567,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt10444.kt") + public void testKt10444() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt10444.kt"); + doTest(fileName); + } + @TestMetadata("kt10483.kt") public void testKt10483() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt10483.kt");