File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed
testData/diagnostics/tests/smartCasts
tests/org/jetbrains/kotlin/checkers Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -15567,6 +15567,12 @@ public void testKt10232() throws Exception {
15567
15567
doTest(fileName);
15568
15568
}
15569
15569
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
+
15570
15576
@TestMetadata("kt10483.kt")
15571
15577
public void testKt10483() throws Exception {
15572
15578
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt10483.kt");
You can’t perform that action at this time.
0 commit comments