Skip to content

Commit 078a53e

Browse files
committed
Minor, add regression test for KT-10444
#KT-10444 Obsolete
1 parent 4a31ad0 commit 078a53e

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// !DIAGNOSTICS: -UNUSED_PARAMETER
2+
// KT-10444 Do not ignore smart (unchecked) casts to the same classifier
3+
4+
class Qwe<T : Any>(val a: T?) {
5+
fun test1(obj: Any) {
6+
<!UNCHECKED_CAST!>obj as Qwe<T><!>
7+
check(<!DEBUG_INFO_SMARTCAST!>obj<!>.a)
8+
}
9+
10+
fun test1(obj: Qwe<*>) {
11+
<!UNCHECKED_CAST!>obj as Qwe<T><!>
12+
check(<!DEBUG_INFO_SMARTCAST!>obj<!>.a)
13+
}
14+
15+
fun check(a: T?) {
16+
}
17+
}
18+
19+
open class Foo
20+
open class Bar<T: Foo>(open val a: T?, open val b: T?) {
21+
@Suppress("UNCHECKED_CAST")
22+
fun compare(obj: Any) {
23+
if (obj !is Bar<*>) {
24+
throw IllegalArgumentException()
25+
}
26+
if (System.currentTimeMillis() > 100) {
27+
val b = (obj as Bar<T>).b
28+
if (b == null) throw IllegalArgumentException()
29+
check(<!DEBUG_INFO_SMARTCAST!>obj<!>.a, <!DEBUG_INFO_SMARTCAST!>b<!>)
30+
}
31+
}
32+
fun check(a: T?, b: T) {
33+
}
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package
2+
3+
public open class Bar</*0*/ T : Foo> {
4+
public constructor Bar</*0*/ T : Foo>(/*0*/ a: T?, /*1*/ b: T?)
5+
public open val a: T?
6+
public open val b: T?
7+
public final fun check(/*0*/ a: T?, /*1*/ b: T): kotlin.Unit
8+
@kotlin.Suppress(names = {"UNCHECKED_CAST"}) public final fun compare(/*0*/ obj: kotlin.Any): kotlin.Unit
9+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
10+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
11+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
12+
}
13+
14+
public open class Foo {
15+
public constructor Foo()
16+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
17+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
18+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
19+
}
20+
21+
public final class Qwe</*0*/ T : kotlin.Any> {
22+
public constructor Qwe</*0*/ T : kotlin.Any>(/*0*/ a: T?)
23+
public final val a: T?
24+
public final fun check(/*0*/ a: T?): kotlin.Unit
25+
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
26+
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
27+
public final fun test1(/*0*/ obj: Qwe<*>): kotlin.Unit
28+
public final fun test1(/*0*/ obj: kotlin.Any): kotlin.Unit
29+
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
30+
}

compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15567,6 +15567,12 @@ public void testKt10232() throws Exception {
1556715567
doTest(fileName);
1556815568
}
1556915569

15570+
@TestMetadata("kt10444.kt")
15571+
public void testKt10444() throws Exception {
15572+
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt10444.kt");
15573+
doTest(fileName);
15574+
}
15575+
1557015576
@TestMetadata("kt10483.kt")
1557115577
public void testKt10483() throws Exception {
1557215578
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt10483.kt");

0 commit comments

Comments
 (0)