From 2bcdadf17f86414410ee627b748c45d9b7fe795a Mon Sep 17 00:00:00 2001 From: "victor.petukhov" Date: Fri, 28 Dec 2018 15:45:04 +0300 Subject: [PATCH] Add positive diagnostic tests for smartcasts from nullability condition using if expression --- .../smart-casts-sources/p-4/pos/1.1.kt | 1166 +++++++++++ .../smart-casts-sources/p-4/pos/1.10.kt | 371 ++++ .../smart-casts-sources/p-4/pos/1.11.kt | 188 ++ .../smart-casts-sources/p-4/pos/1.12.kt | 1720 +++++++++++++++++ .../smart-casts-sources/p-4/pos/1.13.kt | 1662 ++++++++++++++++ .../smart-casts-sources/p-4/pos/1.14.kt | 67 + .../smart-casts-sources/p-4/pos/1.15.kt | 195 ++ .../smart-casts-sources/p-4/pos/1.16.kt | 405 ++++ .../smart-casts-sources/p-4/pos/1.17.kt | 193 ++ .../smart-casts-sources/p-4/pos/1.18.kt | 259 +++ .../smart-casts-sources/p-4/pos/1.2.kt | 362 ++++ .../smart-casts-sources/p-4/pos/1.3.kt | 318 +++ .../smart-casts-sources/p-4/pos/1.4.kt | 304 +++ .../smart-casts-sources/p-4/pos/1.5.kt | 296 +++ .../smart-casts-sources/p-4/pos/1.6.kt | 1009 ++++++++++ .../smart-casts-sources/p-4/pos/1.7.kt | 354 ++++ .../smart-casts-sources/p-4/pos/1.8.kt | 128 ++ .../smart-casts-sources/p-4/pos/1.9.kt | 427 ++++ .../DiagnosticsTestSpecGenerated.java | 155 ++ 19 files changed, 9579 insertions(+) create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.1.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.10.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.11.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.13.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.14.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.15.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.16.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.17.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.18.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.2.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.3.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.4.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.5.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.6.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.7.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.8.kt create mode 100644 compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.9.kt diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.1.kt new file mode 100644 index 00000000000..a54cd4ca25f --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.1.kt @@ -0,0 +1,1166 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 1 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) using if expression and simple types. + * HELPERS: classes, objects, typealiases, properties, enumClasses + */ + +// FILE: other_package.kt + +package otherpackage + +// TESTCASE NUMBER: 13 +class Case13 {} + +// TESTCASE NUMBER: 14 +typealias Case14 = String? + +// FILE: main.kt + +import otherpackage.* + +// TESTCASE NUMBER: 1 +fun case_1(x: Any?) { + if (x != null) { + x + x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 2 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28159 + */ +fun case_2(x: Nothing?) { + if (x !== null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 3 +fun case_3() { + if (Object.prop_1 == null) + else { + Object.prop_1 + Object.prop_1.equals(Object.prop_1) + } +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Char?) { + if (x != null && true) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 5 +fun case_5() { + val x: Unit? = null + + if (x !== null) x + if (x !== null) x.equals(x) +} + +// TESTCASE NUMBER: 6 +fun case_6(x: EmptyClass?) { + val y = true + + if (x != null && !y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 7 +fun case_7() { + if (nullableNumberProperty != null || nullableNumberProperty != null) { + nullableNumberProperty + nullableNumberProperty.equals(nullableNumberProperty) + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: TypealiasNullableString) { + if (x !== null && x != null) x + if (x !== null && x != null) x.equals(x) +} + +// TESTCASE NUMBER: 9 +fun case_9(x: TypealiasNullableString?) { + if (x === null) { + + } else if (false) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 10 +fun case_10() { + val a = Class() + + if (a.prop_4 === null || true) { + if (a.prop_4 != null) { + a.prop_4 + a.prop_4.equals(a.prop_4) + } + } +} + +// TESTCASE NUMBER: 11 +fun case_11(x: TypealiasNullableStringIndirect?, y: TypealiasNullableStringIndirect) { + val t: TypealiasNullableStringIndirect = null + + if (x == null) { + + } else { + if (y != null) { + if (nullableStringProperty == null) { + if (t != null) { + x + x.equals(x) + } + } + } + } +} + +// TESTCASE NUMBER: 12 +fun case_12(x: TypealiasNullableStringIndirect, y: TypealiasNullableStringIndirect) = + & java.io.Serializable}")!>if (x == null) "1" +else if (y === null) x +else if (y === null) x.equals(x) +else "-1" + +// TESTCASE NUMBER: 13 +fun case_13(x: otherpackage.Case13?) = +if (x == null) { + throw Exception() +} else { + x + x.equals(x) +} + +// TESTCASE NUMBER: 14 +class Case14 { + val x: otherpackage.Case14? + init { + x = otherpackage.Case14() + } +} + +fun case_14() { + val a = Case14() + + if (a.x != null) { + if (a.x != null) { + if (a.x !== null) { + if (a.x != null) { + if (a.x != null) { + if (a.x != null) { + if (a.x !== null) { + if (a.x != null) { + if (a.x != null) { + if (a.x !== null) { + if (a.x != null) { + if (a.x != null) { + if (a.x != null) { + if (a.x !== null) { + if (a.x != null) { + if (a.x !== null) { + a.x + a.x.equals(a.x) + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 15 +fun case_15(x: EmptyObject) { + val t = & java.io.Serializable}")!>if (x === null) "" else { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 16 +fun case_16() { + val x: TypealiasNullableNothing = null + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 17 +val case_17 = & java.io.Serializable}")!>if (nullableIntProperty == null) 0 else { + nullableIntProperty + nullableIntProperty.equals(nullableIntProperty) +} + +//TESTCASE NUMBER: 18 +fun case_18(a: DeepObject.A.B.C.D.E.F.G.J?) { + if (a != null) { + a + a.equals(a) + } +} + +// TESTCASE NUMBER: 19 +fun case_19(b: Boolean) { + val a = if (b) { + object { + val B19 = if (b) { + object { + val C19 = if (b) { + object { + val D19 = if (b) { + object { + val x: Number? = 10 + } + } else null + } + } else null + } + } else null + } + } else null + + if (a != null && a.B19 != null && a.B19.C19 != null && a.B19.C19.D19 != null && a.B19.C19.D19.x != null) { + a.B19.C19.D19.x + a.B19.C19.D19.x.equals(null) + } +} + +// TESTCASE NUMBER: 20 +fun case_20(b: Boolean) { + val a = object { + val B19 = object { + val C19 = object { + val D19 = if (b) { + object {} + } else null + } + } + } + + if (a.B19.C19.D19 !== null) { + .B19..C19..D19. & case_20..B19..C19..D19.?")!>a.B19.C19.D19 + .B19..C19..D19."), DEBUG_INFO_SMARTCAST!>a.B19.C19.D19.equals(a.B19.C19.D19) + } +} + +// TESTCASE NUMBER: 21 +fun case_21() { + if (EnumClassWithNullableProperty.B.prop_1 !== null) { + EnumClassWithNullableProperty.B.prop_1 + EnumClassWithNullableProperty.B.prop_1.equals(EnumClassWithNullableProperty.B.prop_1) + } +} + +// TESTCASE NUMBER: 22 +fun case_22(a: (() -> Unit)?) { + if (a != null) { + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a() + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a().equals(a) + } +} + +// TESTCASE NUMBER: 23 +fun case_23(a: ((Float) -> Int?)?, b: Float?) { + if (a != null && b !== null) { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + if (x != null) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 24 +fun case_24(a: ((() -> Unit) -> Unit)?, b: (() -> Unit)?) = + if (a !== null && b !== null) { + kotlin.Unit) -> kotlin.Unit)? & (() -> kotlin.Unit) -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a( kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>b) + kotlin.Unit) -> kotlin.Unit)? & (() -> kotlin.Unit) -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a(b) + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>b.equals(null) + } else null + +// TESTCASE NUMBER: 25 +fun case_25(b: Boolean) { + val x = { + if (b) object { + val a = 10 + } else null + } + + val y = if (b) x else null + + if (y !== null) { + val z = .?")!> case_25..?)? & () -> case_25..?"), DEBUG_INFO_SMARTCAST!>y() + + if (z != null) { + . & case_25..?"), DEBUG_INFO_SMARTCAST!>z.a + . & case_25..?"), DEBUG_INFO_SMARTCAST!>z.a.equals(z.a) + } + } +} + +// TESTCASE NUMBER: 26 +fun case_26(a: ((Float) -> Int?)?, b: Float?) { + if (a != null == true && b != null == true) { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + if (x != null == true) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 27 +fun case_27() { + if (Object.prop_1 == null == true == true == true == true == true == true == true == true == true == true == true == true == true == true) + else { + Object.prop_1 + Object.prop_1.equals(Object.prop_1) + } +} + +//TESTCASE NUMBER: 28 +fun case_28(a: DeepObject.A.B.C.D.E.F.G.J?) = + if (a != null == true == false == false == false == true == false == true == false == false == true == true) { + a.x + a.equals(a) + } else -1 + +// TESTCASE NUMBER: 29 +open class Case29(a: Int?, val b: Float?, private val c: Unit?, protected val d: String?, internal val e: Char?, public val f: Any?) { + val x: Char? = '.' + private val y: Unit? = kotlin.Unit + protected val z: Int? = 12 + public val u: String? = "..." + val s: Any? + val v: Int? + val w: Number? + val t: String? = if (u != null) this.u else null + + init { + if (a != null) a.equals(a) + if (a != null) a + + if (b != null) b.equals(b) + if (b != null) b + if (this.b != null) this.b + if (this.b != null) this.b.equals(this.b) + if (this.b != null) b + if (this.b != null) b.equals(b) + if (b != null) this.b + if (b != null) this.b.equals(b) + if (b != null || this.b != null) b.equals(b) + if (b != null || this.b != null) b + if (b != null || this.b != null) this.b.equals(this.b) + if (b != null || this.b != null) this.b + + if (c != null) c.equals(c) + if (c != null) c + if (this.c != null) this.c.equals(c) + if (this.c != null) this.c + if (c != null) this.c.equals(this.c) + if (c != null) this.c + if (this.c != null) c.equals(this.c) + if (this.c != null) c + if (c != null || this.c != null) c.equals(c) + if (c != null || this.c != null) c + if (c != null || this.c != null) this.c.equals(this.c) + if (c != null || this.c != null) this.c + + if (d != null) d.equals(d) + if (d != null) d + if (this.d != null) this.d.equals(d) + if (this.d != null) this.d + if (d != null) this.d.equals(d) + if (d != null) this.d + if (this.d != null) d.equals(d) + if (this.d != null) d + if (d != null || this.d != null) d.equals(d) + if (d != null || this.d != null) d + if (d != null || this.d != null) this.d.equals(d) + if (d != null || this.d != null) this.d + + if (e != null) e.equals(e) + if (e != null) e + if (this.e != null) this.e.equals(e) + if (this.e != null) this.e + if (this.e != null) e.equals(e) + if (this.e != null) e + if (e != null) this.e.equals(e) + if (e != null) this.e + if (e != null || this.e != null) e.equals(e) + if (e != null || this.e != null) e + if (e != null || this.e != null) this.e.equals(e) + if (e != null || this.e != null) this.e + + if (f != null) f.equals(f) + if (f != null) f + if (this.f != null) this.f.equals(f) + if (this.f != null) this.f + if (this.f != null) f.equals(f) + if (this.f != null) f + if (f != null) this.f.equals(f) + if (f != null) this.f + if (f != null || this.f != null) f.equals(f) + if (f != null || this.f != null) f + if (f != null || this.f != null) this.f.equals(f) + if (f != null || this.f != null) this.f + + if (x != null) x.equals(x) + if (x != null) x + if (this.x != null) this.x.equals(x) + if (this.x != null) this.x + if (x != null) this.x.equals(x) + if (x != null) this.x + if (this.x != null) x.equals(x) + if (this.x != null) x + if (x != null || this.x != null) x.equals(x) + if (x != null || this.x != null) x + if (x != null || this.x != null) this.x.equals(x) + if (x != null || this.x != null) this.x + + if (y != null) y.equals(y) + if (y != null) y + if (this.y != null) this.y.equals(y) + if (this.y != null) this.y + if (this.y != null) y.equals(y) + if (this.y != null) y + if (y != null) this.y.equals(y) + if (y != null) this.y + if (y != null || this.y != null) y.equals(y) + if (y != null || this.y != null) y + if (y != null || this.y != null) this.y.equals(y) + if (y != null || this.y != null) this.y + + if (z != null) z.equals(z) + if (z != null) z + if (this.z != null) this.z.equals(z) + if (this.z != null) this.z + if (z != null) this.z.equals(z) + if (z != null) this.z + if (this.z != null) z.equals(z) + if (this.z != null) z + if (z != null || this.z != null) z + if (z != null || this.z != null) z.equals(z) + if (z != null || this.z != null) this.z + if (z != null || this.z != null) this.z.equals(z) + + if (u != null) u.equals(u) + if (u != null) u + if (this.u != null) this.u.equals(u) + if (this.u != null) this.u + if (this.u != null) u.equals(u) + if (this.u != null) u + if (u != null) this.u.equals(u) + if (u != null) this.u + if (u != null || this.u != null) u.equals(u) + if (u != null || this.u != null) u + if (u != null || this.u != null) this.u.equals(u) + if (u != null || this.u != null) this.u + + v = 0 + v.equals(v) + v + if (v != null) v.equals(v) + if (v != null) v + if (this.v != null) v.equals(v) + if (this.v != null) v + if (v != null || this.v != null) v.equals(v) + if (v != null || this.v != null) v + if (v != null || this.v != null) this.v.equals(v) + if (v != null || this.v != null) this.v + + w = if (null != null) 10 else null + w + if (w != null) w.equals(w) + if (w != null) w + if (this.w != null) w.equals(w) + if (this.w != null) w + if (w != null || this.w != null) w.equals(w) + if (w != null || this.w != null) w + if (w != null || this.w != null) this.w.equals(w) + if (w != null || this.w != null) this.w + + s = null + s.equals(s) + s + if (s != null) s.equals(s) + if (s != null) s + if (this.s != null) s.equals(s) + if (this.s != null) s + if (s != null || this.s != null) s.equals(s) + if (s != null || this.s != null) s + if (s != null || this.s != null) this.s.equals(s) + if (s != null || this.s != null) this.s + } + + fun test() { + if (b != null) b.equals(b) + if (b != null) b + + if (c != null) c.equals(c) + if (c != null) c + + if (d != null) d.equals(d) + if (d != null) d + + if (e != null) e.equals(e) + if (e != null) e + + if (f != null) f.equals(f) + if (f != null) f + + if (x != null) x.equals(x) + if (x != null) x + + if (y != null) y.equals(y) + if (y != null) y + + if (z != null) z.equals(z) + if (z != null) z + + if (u != null) u.equals(u) + if (u != null) u + + if (v != null) v.equals(v) + if (v != null) v + + if (w != null) w.equals(w) + if (w != null) w + + if (s != null) s.equals(s) + if (s != null) s + } +} + +fun case_29(a: Case29) { + if (a.x !== null) a.x.equals(a.x) + if (a.x !== null) a.x + if (a.b !== null) a.b.equals(a.b) + if (a.b !== null) a.b + if (a.e !== null) a.e.equals(a.e) + if (a.e !== null) a.e + if (a.f !== null) a.f.equals(a.f) + if (a.f !== null) a.f + if (a.v != null) a.v.equals(a.v) + if (a.v != null) a.v + if (a.w != null) a.w.equals(a.w) + if (a.w != null) a.w + if (a.s != null) a.s.equals(a.s) + if (a.s != null) a.s +} + +// TESTCASE NUMBER: 30 +sealed class Case30(a: Int?, val b: Float?, private val c: Unit?, protected val d: String?, internal val e: Char?, public val f: Any?) { + val x: Char? = '.' + private val y: Unit? = kotlin.Unit + protected val z: Int? = 12 + public val u: String? = "..." + val s: Any? + val v: Int? + val w: Number? + val t: String? = if (u != null) this.u else null + + init { + if (a != null) a.equals(a) + if (a != null) a + + if (b != null) b.equals(b) + if (b != null) b + if (this.b != null) this.b.equals(this.b) + if (this.b != null) this.b + if (this.b != null) b.equals(b) + if (this.b != null) b + if (b != null) this.b.equals(this.b) + if (b != null) this.b + if (b != null || this.b != null) b.equals(b) + if (b != null || this.b != null) b + if (b != null || this.b != null) this.b.equals(this.b) + if (b != null || this.b != null) this.b + + if (c != null) c.equals(c) + if (c != null) c + if (this.c != null) this.c.equals(this.c) + if (this.c != null) this.c + if (c != null) this.c.equals(this.c) + if (c != null) this.c + if (this.c != null) c.equals(c) + if (this.c != null) c + if (c != null || this.c != null) c.equals(c) + if (c != null || this.c != null) c + if (c != null || this.c != null) this.c.equals(this.c) + if (c != null || this.c != null) this.c + + if (d != null) d.equals(d) + if (d != null) d + if (this.d != null) this.d.equals(this.d) + if (this.d != null) this.d + if (d != null) this.d.equals(this.d) + if (d != null) this.d + if (this.d != null) d.equals(d) + if (this.d != null) d + if (d != null || this.d != null) d.equals(d) + if (d != null || this.d != null) d + if (d != null || this.d != null) this.d.equals(this.d) + if (d != null || this.d != null) this.d + + if (e != null) e.equals(e) + if (e != null) e + if (this.e != null) this.e.equals(this.e) + if (this.e != null) this.e + if (this.e != null) e.equals(e) + if (this.e != null) e + if (e != null) this.e.equals(this.e) + if (e != null) this.e + if (e != null || this.e != null) e.equals(e) + if (e != null || this.e != null) e + if (e != null || this.e != null) this.e.equals(this.e) + if (e != null || this.e != null) this.e + + if (f != null) f.equals(f) + if (f != null) f + if (this.f != null) this.f.equals(this.f) + if (this.f != null) this.f + if (this.f != null) f.equals(f) + if (this.f != null) f + if (f != null) this.f.equals(this.f) + if (f != null) this.f + if (f != null || this.f != null) f.equals(f) + if (f != null || this.f != null) f + if (f != null || this.f != null) this.f.equals(this.f) + if (f != null || this.f != null) this.f + + if (x != null) x.equals(x) + if (x != null) x + if (this.x != null) this.x.equals(this.x) + if (this.x != null) this.x + if (x != null) this.x.equals(this.x) + if (x != null) this.x + if (this.x != null) x.equals(x) + if (this.x != null) x + if (x != null || this.x != null) x.equals(x) + if (x != null || this.x != null) x + if (x != null || this.x != null) this.x.equals(this.x) + if (x != null || this.x != null) this.x + + if (y != null) y.equals(y) + if (y != null) y + if (this.y != null) this.y.equals(this.y) + if (this.y != null) this.y + if (this.y != null) y.equals(y) + if (this.y != null) y + if (y != null) this.y.equals(this.y) + if (y != null) this.y + if (y != null || this.y != null) y.equals(y) + if (y != null || this.y != null) y + if (y != null || this.y != null) this.y.equals(this.y) + if (y != null || this.y != null) this.y + + if (z != null) z.equals(z) + if (z != null) z + if (this.z != null) this.z.equals(this.z) + if (this.z != null) this.z + if (z != null) this.z.equals(this.z) + if (z != null) this.z + if (this.z != null) z.equals(z) + if (this.z != null) z + if (z != null || this.z != null) z.equals(z) + if (z != null || this.z != null) z + if (z != null || this.z != null) this.z.equals(this.z) + if (z != null || this.z != null) this.z + + if (u != null) u.equals(u) + if (u != null) u + if (this.u != null) this.u.equals(this.u) + if (this.u != null) this.u + if (this.u != null) u.equals(u) + if (this.u != null) u + if (u != null) this.u.equals(this.u) + if (u != null) this.u + if (u != null || this.u != null) u.equals(u) + if (u != null || this.u != null) u + if (u != null || this.u != null) this.u.equals(this.u) + if (u != null || this.u != null) this.u + + v = 0 + v.equals(v) + v + if (v != null) v.equals(v) + if (v != null) v + if (this.v != null) v.equals(v) + if (this.v != null) v + if (v != null || this.v != null) v.equals(v) + if (v != null || this.v != null) v + if (v != null || this.v != null) this.v.equals(this.v) + if (v != null || this.v != null) this.v + + w = if (null != null) 10 else null + w + if (w != null) w.equals(w) + if (w != null) w + if (this.w != null) w.equals(w) + if (this.w != null) w + if (w != null || this.w != null) w.equals(w) + if (w != null || this.w != null) w + if (w != null || this.w != null) this.w.equals(this.w) + if (w != null || this.w != null) this.w + + s = null + s.equals(s) + s + if (s != null) s.equals(s) + if (s != null) s + if (this.s != null) s.equals(s) + if (this.s != null) s + if (s != null || this.s != null) s.equals(s) + if (s != null || this.s != null) s + if (s != null || this.s != null) this.s.equals(this.s) + if (s != null || this.s != null) this.s + } + + fun test() { + if (b != null) b.equals(b) + if (b != null) b + + if (c != null) c.equals(c) + if (c != null) c + + if (d != null) d.equals(d) + if (d != null) d + + if (e != null) e.equals(e) + if (e != null) e + + if (f != null) f.equals(f) + if (f != null) f + + if (x != null) x.equals(x) + if (x != null) x + + if (y != null) y.equals(y) + if (y != null) y + + if (z != null) z.equals(z) + if (z != null) z + + if (u != null) u.equals(u) + if (u != null) u + + if (v != null) v.equals(v) + if (v != null) v + + if (w != null) w.equals(w) + if (w != null) w + + if (s != null) s.equals(s) + if (s != null) s + } +} + +fun case_30(a: Case30) { + if (a.x !== null) a.x.equals(a.x) + if (a.x !== null) a.x + if (a.b !== null) a.b.equals(a.b) + if (a.b !== null) a.b + if (a.e !== null) a.e.equals(a.e) + if (a.e !== null) a.e + if (a.f !== null) a.f.equals(a.f) + if (a.f !== null) a.f + if (a.v != null) a.v.equals(a.v) + if (a.v != null) a.v + if (a.w != null) a.w.equals(a.w) + if (a.w != null) a.w + if (a.s != null) a.s.equals(a.s) + if (a.s != null) a.s +} + +// TESTCASE NUMBER: 31 +enum class Case31(a: Int?, val b: Float?, private val c: Unit?, protected val d: String?, internal val e: Char?, public val f: Any?) { + A(1, 2f, kotlin.Unit, "", ',', null), B(1, 2f, kotlin.Unit, "", ',', null), C(1, 2f, kotlin.Unit, "", ',', null); + + val x: Char? = '.' + private val y: Unit? = kotlin.Unit + protected val z: Int? = 12 + public val u: String? = "..." + val s: Any? + val v: Int? + val w: Number? + val t: String? = if (u != null) this.u else null + + init { + if (a != null) a.equals(a) + if (a != null) a + + if (b != null) b.equals(b) + if (b != null) b + if (this.b != null) this.b.equals(this.b) + if (this.b != null) this.b + if (this.b != null) b.equals(b) + if (this.b != null) b + if (b != null) this.b.equals(this.b) + if (b != null) this.b + if (b != null || this.b != null) b.equals(b) + if (b != null || this.b != null) b + if (b != null || this.b != null) this.b.equals(this.b) + if (b != null || this.b != null) this.b + + if (c != null) c.equals(c) + if (c != null) c + if (this.c != null) this.c.equals(this.c) + if (this.c != null) this.c + if (c != null) this.c.equals(this.c) + if (c != null) this.c + if (this.c != null) c.equals(c) + if (this.c != null) c + if (c != null || this.c != null) c.equals(c) + if (c != null || this.c != null) c + if (c != null || this.c != null) this.c.equals(this.c) + if (c != null || this.c != null) this.c + + if (d != null) d.equals(d) + if (d != null) d + if (this.d != null) this.d.equals(this.d) + if (this.d != null) this.d + if (d != null) this.d.equals(this.d) + if (d != null) this.d + if (this.d != null) d.equals(d) + if (this.d != null) d + if (d != null || this.d != null) d.equals(d) + if (d != null || this.d != null) d + if (d != null || this.d != null) this.d.equals(this.d) + if (d != null || this.d != null) this.d + + if (e != null) e.equals(e) + if (e != null) e + if (this.e != null) this.e.equals(this.e) + if (this.e != null) this.e + if (this.e != null) e.equals(e) + if (this.e != null) e + if (e != null) this.e.equals(this.e) + if (e != null) this.e + if (e != null || this.e != null) e.equals(e) + if (e != null || this.e != null) e + if (e != null || this.e != null) this.e.equals(this.e) + if (e != null || this.e != null) this.e + + if (f != null) f.equals(f) + if (f != null) f + if (this.f != null) this.f.equals(this.f) + if (this.f != null) this.f + if (this.f != null) f.equals(f) + if (this.f != null) f + if (f != null) this.f.equals(this.f) + if (f != null) this.f + if (f != null || this.f != null) f.equals(f) + if (f != null || this.f != null) f + if (f != null || this.f != null) this.f.equals(this.f) + if (f != null || this.f != null) this.f + + if (x != null) x.equals(x) + if (x != null) x + if (this.x != null) this.x.equals(this.x) + if (this.x != null) this.x + if (x != null) this.x.equals(this.x) + if (x != null) this.x + if (this.x != null) x.equals(x) + if (this.x != null) x + if (x != null || this.x != null) x.equals(x) + if (x != null || this.x != null) x + if (x != null || this.x != null) this.x.equals(this.x) + if (x != null || this.x != null) this.x + + if (y != null) y.equals(y) + if (y != null) y + if (this.y != null) this.y.equals(this.y) + if (this.y != null) this.y + if (this.y != null) y.equals(y) + if (this.y != null) y + if (y != null) this.y.equals(this.y) + if (y != null) this.y + if (y != null || this.y != null) y.equals(y) + if (y != null || this.y != null) y + if (y != null || this.y != null) this.y.equals(this.y) + if (y != null || this.y != null) this.y + + if (z != null) z.equals(z) + if (z != null) z + if (this.z != null) this.z.equals(this.z) + if (this.z != null) this.z + if (z != null) this.z.equals(this.z) + if (z != null) this.z + if (this.z != null) z.equals(z) + if (this.z != null) z + if (z != null || this.z != null) z.equals(z) + if (z != null || this.z != null) z + if (z != null || this.z != null) this.z.equals(this.z) + if (z != null || this.z != null) this.z + + if (u != null) u.equals(u) + if (u != null) u + if (this.u != null) this.u.equals(this.u) + if (this.u != null) this.u + if (this.u != null) u.equals(u) + if (this.u != null) u + if (u != null) this.u.equals(this.u) + if (u != null) this.u + if (u != null || this.u != null) u.equals(u) + if (u != null || this.u != null) u + if (u != null || this.u != null) this.u.equals(this.u) + if (u != null || this.u != null) this.u + + v = 0 + v.equals(v) + v + if (v != null) v.equals(v) + if (v != null) v + if (this.v != null) v.equals(v) + if (this.v != null) v + if (v != null || this.v != null) v.equals(v) + if (v != null || this.v != null) v + if (v != null || this.v != null) this.v.equals(this.v) + if (v != null || this.v != null) this.v + + w = if (null != null) 10 else null + if (w != null) w.equals(w) + if (w != null) w + if (this.w != null) w.equals(w) + if (this.w != null) w + if (w != null || this.w != null) w.equals(w) + if (w != null || this.w != null) w + if (w != null || this.w != null) this.w.equals(this.w) + if (w != null || this.w != null) this.w + + s = null + s.equals(s) + s + if (s != null) s.equals(s) + if (s != null) s + if (this.s != null) s.equals(s) + if (this.s != null) s + if (s != null || this.s != null) s.equals(s) + if (s != null || this.s != null) s + if (s != null || this.s != null) this.s.equals(this.s) + if (s != null || this.s != null) this.s + } + + fun test() { + if (b != null) b.equals(b) + if (b != null) b + + if (c != null) c.equals(c) + if (c != null) c + + if (d != null) d.equals(d) + if (d != null) d + + if (e != null) e.equals(e) + if (e != null) e + + if (f != null) f.equals(f) + if (f != null) f + + if (x != null) x.equals(x) + if (x != null) x + + if (y != null) y.equals(y) + if (y != null) y + + if (z != null) z.equals(z) + if (z != null) z + + if (u != null) u.equals(u) + if (u != null) u + + if (v != null) v.equals(v) + if (v != null) v + + if (w != null) w.equals(w) + if (w != null) w + + if (s != null) s.equals(s) + if (s != null) s + } +} + +fun case_31(a: Case31) { + if (a.x !== null) a.x.equals(a.x) + if (a.x !== null) a.x + if (a.b !== null) a.b.equals(a.b) + if (a.b !== null) a.b + if (a.e !== null) a.e.equals(a.e) + if (a.e !== null) a.e + if (a.f !== null) a.f.equals(a.f) + if (a.f !== null) a.f + if (a.v != null) a.v.equals(a.v) + if (a.v != null) a.v + if (a.w != null) a.w.equals(a.w) + if (a.w != null) a.w + if (a.s != null) a.s.equals(a.s) + if (a.s != null) a.s + + if (Case31.A.b != null) Case31.A.b.equals(Case31.A.b) + if (Case31.A.b != null) Case31.A.b + if (Case31.A.e != null) Case31.A.e.equals(Case31.A.e) + if (Case31.A.e != null) Case31.A.e + if (Case31.A.f != null) Case31.A.f.equals(Case31.A.f) + if (Case31.A.f != null) Case31.A.f +} + +// TESTCASE NUMBER: 32 +object Case32 { + val x: Char? = '.' + private val y: Unit? = kotlin.Unit + public val u: String? = "..." + val s: Any? + val v: Int? + val w: Number? + val t: String? = if (u != null) this.u else null + + init { + if (x != null) x.equals(x) + if (x != null) x + if (this.x != null) this.x.equals(this.x) + if (this.x != null) this.x + if (x != null) this.x.equals(this.x) + if (x != null) this.x + if (this.x != null) x.equals(x) + if (this.x != null) x + if (x != null || this.x != null) x.equals(x) + if (x != null || this.x != null) x + if (x != null || this.x != null) this.x.equals(this.x) + if (x != null || this.x != null) this.x + + if (y != null) y.equals(y) + if (y != null) y + if (this.y != null) this.y.equals(this.y) + if (this.y != null) this.y + if (this.y != null) y.equals(y) + if (this.y != null) y + if (y != null) this.y.equals(this.y) + if (y != null) this.y + if (y != null || this.y != null) y.equals(y) + if (y != null || this.y != null) y + if (y != null || this.y != null) this.y.equals(this.y) + if (y != null || this.y != null) this.y + + if (u != null) u.equals(u) + if (u != null) u + if (this.u != null) this.u.equals(this.u) + if (this.u != null) this.u + if (this.u != null) u.equals(u) + if (this.u != null) u + if (u != null) this.u.equals(this.u) + if (u != null) this.u + if (u != null || this.u != null) u.equals(u) + if (u != null || this.u != null) u + if (u != null || this.u != null) this.u.equals(this.u) + if (u != null || this.u != null) this.u + + v = 0 + v.equals(v) + v + if (v != null) v.equals(v) + if (v != null) v + if (this.v != null) v.equals(v) + if (this.v != null) v + if (v != null || this.v != null) v.equals(v) + if (v != null || this.v != null) v + if (v != null || this.v != null) this.v.equals(this.v) + if (v != null || this.v != null) this.v + + w = if (null != null) 10 else null + if (w != null) w.equals(w) + if (w != null) w + if (this.w != null) w.equals(w) + if (this.w != null) w + if (w != null || this.w != null) w.equals(w) + if (w != null || this.w != null) w + if (w != null || this.w != null) this.w.equals(this.w) + if (w != null || this.w != null) this.w + + s = null + s.equals(s) + s + if (s != null) s.equals(s) + if (s != null) s + if (this.s != null) s.equals(s) + if (this.s != null) s + if (s != null || this.s != null) s.equals(s) + if (s != null || this.s != null) s + if (s != null || this.s != null) this.s.equals(this.s) + if (s != null || this.s != null) this.s + } + + fun test() { + if (x != null) x.equals(x) + if (x != null) x + + if (y != null) y.equals(y) + if (y != null) y + + if (u != null) u.equals(u) + if (u != null) u + + if (v != null) v.equals(v) + if (v != null) v + + if (w != null) w.equals(w) + if (w != null) w + + if (s != null) s.equals(s) + if (s != null) s + } +} + +fun case_32(a: Case32) { + if (a.x != null) a.x.equals(a.x) + if (a.x != null) a.x + if (a.v != null) a.v.equals(a.v) + if (a.v != null) a.v + if (a.w != null) a.w.equals(a.w) + if (a.w != null) a.w + if (a.s != null) a.s.equals(a.s) + if (a.s != null) a.s +} + +// TESTCASE NUMBER: 33 +fun case_33(a: Int?, b: Int = if (a != null) a else 0) { + a + b.equals(b) + b +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.10.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.10.kt new file mode 100644 index 00000000000..797f2a0ac6a --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.10.kt @@ -0,0 +1,371 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 10 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) using if expression and wrapped-unwrapped types. + * HELPERS: classes, functions + */ + +// TESTCASE NUMBER: 1 +fun case_1() { + val x = expandInv(Inv(select(10, null))) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 2 +fun case_2() { + val x = expandOut(Out(select(10, null))) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 3 +fun case_3() { + val x = expandInv(Inv(select(10, null))) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 4 +fun case_4() { + val x = expandOut(Out(select(10, null))) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 5 +fun case_5() { + val x = expandIn(In()) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 6 +fun case_6() { + val x = expandIn(In()) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 7 +fun case_7(x: MutableMap) = select(x.values.first(), x.keys.first()) + +fun case_7() { + val x = case_7(mutableMapOf(10 to 10)) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: MutableMap) = select(x.values.first(), x.keys.first()) + +fun case_8() { + val x = case_8(mutableMapOf(10 to null)) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 9 +fun case_9(x: MutableMap) = select(x.values.first(), x.keys.first()) + +fun case_9() { + val x = case_9(mutableMapOf(null to 10)) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 10 +fun case_10(x: MutableMap) = select(x.values.first(), x.keys.first()) + +fun case_10() { + val x = case_10(mutableMapOf(10 to 10)) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 11 +fun case_11(x: MutableMap) = select(x.values.first(), x.keys.first()) + +fun case_11() { + val x = case_11(mutableMapOf(10 to 10)) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 12 +fun case_12(x: MutableMap) = select(x.values.first(), x.keys.first()) + +fun case_12() { + val x = case_12(mutableMapOf(10 to 11)) + + if (x != null) { + x + x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 13 + * ISSUES: KT-28334 + * NOTE: before fix of the issue type is inferred to {Int? & Byte? & Short? & Long?} (smart cast from {Int? & Byte? & Short? & Long?}?) + */ +fun case_13(x: Out?, y: Out) = select(x, y) + +fun case_13() { + val x = case_13(Out(), Out()) + + if (x != null) { + & Out?")!>x + & Out?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + val y = x.get() + if (y != null) { + y + y.equals(y) + } + } +} + +// TESTCASE NUMBER: 14 +fun case_14(x: Out?, y: Out) = select(x, y) + +fun case_14() { + val x = case_14(Out(), Out()) + + if (x != null) { + & Out?")!>x + & Out?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + val y = x.get() + if (y != null) { + y + y.equals(y) + } + } +} + +// TESTCASE NUMBER: 15 +fun case_15(x: Out, y: Out?) = select(x, y) + +fun case_15() { + val x = case_15(Out(), Out()) + + if (x != null) { + & Out?")!>x + & Out?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + val y = x.get() + if (y != null) { + y + y.equals(y) + } + } +} + +/* + * TESTCASE NUMBER: 16 + * ISSUES: KT-28334 + * NOTE: before fix of the issue type is inferred to {Int? & Byte? & Short? & Long?} (smart cast from {Int? & Byte? & Short? & Long?}?) + */ +fun case_16(x: Out, y: Out) = select(x, select(y, null)) + +fun case_16() { + val x = case_16(Out(), Out()) + + if (x != null) { + & Out?")!>x + & Out?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + val y = x.get() + if (y != null) { + y + y.equals(y) + } + } +} + +// TESTCASE NUMBER: 17 +fun case_17(x: Out, y: Out) = select(x, select(y, null)) + +fun case_17() { + val x = case_17(Out(), Out()) + + if (x != null) { + & Out?")!>x + & Out?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + val y = x.get() + if (y != null) { + y + y.equals(y) + } + } +} + +/* + * TESTCASE NUMBER: 18 + * ISSUES: KT-28334 + * NOTE: before fix of the issue type is inferred to {Int? & Byte? & Short? & Long?} (smart cast from {Int? & Byte? & Short? & Long?}?) + */ +fun case_18(x: Out, y: Out) = select(x, y) + +fun case_18() { + val x = case_18(Out(), Out()) + + ")!>x + ")!>x.equals(x) + val y = x.get() + if (y != null) { + y + y.equals(y) + } +} + +// TESTCASE NUMBER: 19 +fun case_19(x: Out, y: Out) = select(x, y) + +fun case_19() { + val x = case_19(Out(), Out()) + + ")!>x + ")!>x.equals(x) + val y = x.get() + if (y != null) { + y + y.equals(y) + } +} + +// TESTCASE NUMBER: 20 +fun case_20(x: Out, y: Out) = select(x.get(), y.get()) + +fun case_20(y: Int?) { + val x = case_20(Out(y), Out()) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 21 +fun case_21(x: Out, y: Out) = select(x.get(), y.get()) + +fun case_21(y: Int?) { + val x = case_21(Out(y), Out()) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 22 +fun case_22(x: Out, y: Out): T? = select(x.get(), y.get()) + +fun case_22(y: Int?) { + val x = case_22(Out(y), Out()) + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 23 +fun case_23(x: Out, y: Out): T = select(x.get(), y.get()) + +fun case_23(y: Int?) { + val x = case_13(Out(y), Out()) + + if (x != null) { + & Out?")!>x + & Out?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + } +} + +// TESTCASE NUMBER: 24 +fun case_24(x: Out, y: Out) where F : E? = select(x.get(), y.get()) + +fun case_24(y: Int) { + val x = case_13(Out(y), Out()) + + if (x != null) { + & Out?")!>x + & Out?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 25 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-29054 + */ +fun , C: Out, D: Out, E: Out, F> case_25(x: F, y: Out) where F : Out = + select(x.get()?.get()?.get()?.get()?.get(), y.get().get().get()) + +fun case_25(y: Int) { + val x = case_25(Out(Out(Out(Out(Out(y))))), Out(Out(Out(y)))) + + if (x != null) { + x + x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 26 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-29054 + */ +fun , C: Out, D: Out, E: Out, F> case_26(x: F, y: Out) where F : Out = + select(x.get()?.get()?.get()?.get()?.get(), y.get().get().get()) + +fun case_26(y: Int) { + val x = case_26(Out(Out(Out(Out(Out(y))))), Out(Out(Out(y)))) + + if (x != null) { + x + x.equals(x) + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.11.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.11.kt new file mode 100644 index 00000000000..804c7ed623e --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.11.kt @@ -0,0 +1,188 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 11 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) using if expression and wrapped-unwrapped intersection types. + * HELPERS: classes, functions, interfaces + */ + +// TESTCASE NUMBER: 1 +fun , C: Out> case_1(a: C, b: B) = select(a.x, b.x) + +fun case_1() { + val x = case_1(Out(10), Inv(0.1)) + + if (x != null) { + & Number} & {Comparable<{Byte & Double & Int & Long & Short}> & Number}?")!>x + & Number} & {Comparable<{Byte & Double & Int & Long & Short}> & Number}?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + } +} + +// TESTCASE NUMBER: 2 +fun , C: Out> case_2(a: C, b: B) = select(a.x, b.x) + +fun case_2(y: Int) { + val x = case_2(Out(y), Inv(0.1)) + + if (x != null) { + & Number} & {Comparable<{Double & Int}> & Number}?")!>x + & Number} & {Comparable<{Double & Int}> & Number}?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 3 + * ISSUES: KT-28670 + */ +fun case_3(a: Int?, b: Float?, c: Double?, d: Boolean?) { + when (d) { + true -> a + false -> b + null -> c + }.apply { + ? & Number?}"), DEBUG_INFO_EXPRESSION_TYPE("{Comparable<{Double & Float & Int}>? & Number?}")!>this + if (this != null) { + ? & Number?}"), DEBUG_INFO_EXPRESSION_TYPE("{Comparable<{Double & Float & Int}>? & Number?}")!>this + & Number}"), DEBUG_INFO_EXPRESSION_TYPE("{Comparable<{Double & Float & Int}>? & Number?}"), DEBUG_INFO_SMARTCAST!>this.equals(this) + } + }.let { + ? & Number?}")!>it + if (it != null) { + & Number} & {Comparable<{Double & Float & Int}>? & Number?}")!>it + & Number} & {Comparable<{Double & Float & Int}>? & Number?}"), DEBUG_INFO_SMARTCAST!>it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 4 + * ISSUES: KT-28670 + */ +fun case_4(a: Interface1?, b: Interface2?, c: Boolean) { + a as Interface2? + b as Interface1? + val x = when (c) { + true -> a + false -> b + } + + x.apply { + this + if (this != null) { + this + this.equals(this) + } + } + x.let { + it + if (it != null) { + it + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 5 + * ISSUES: KT-28670 + */ +fun case_5(a: Interface1?, b: Interface2?, d: Boolean) { + a as Interface2? + b as Interface1 + val x = when (d) { + true -> a + false -> b + } + + x.apply { + if (this != null) { + this + this.equals(this) + } + } + x.let { + if (it != null) { + it + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 6 + * ISSUES: KT-28670 + */ +fun case_6(a: Interface1?, b: Interface2, d: Boolean) { + a as Interface2? + b as Interface1 + val x = when (d) { + true -> a + false -> b + } + + x.apply { + this as Interface3 + this + if (this != null) { + this + this.equals(this) + this.itest1() + this.itest2() + } + } + x.let { + it as Interface3 + it + if (it != null) { + it + it.equals(it) + it.itest1() + it.itest2() + } + } +} + +/* + * TESTCASE NUMBER: 7 + * ISSUES: KT-28670 + */ +fun case_7(a: Interface1?, b: Interface2?, d: Boolean) { + a as Interface2? + b as Interface1? + val x = when (d) { + true -> a + false -> b + } + + x.apply { + this as Interface3? + this + if (this != null) { + this + this.equals(this) + this.itest1() + this.itest2() + } + } + x.let { + it as Interface3? + it + if (it != null) { + it + it.equals(it) + it.itest1() + it.itest2() + } + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt new file mode 100644 index 00000000000..cefb93d0ae3 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt @@ -0,0 +1,1720 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 12 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) on generic receivers using if expression. + * HELPERS: classes, interfaces + */ + +// TESTCASE NUMBER: 1 +fun T.case_1() { + if (this != null) { + equals(this) + apply { equals(this); this.equals(this) } + also { it.equals(this) } + } +} + +// TESTCASE NUMBER: 2 +fun T?.case_2() { + if (this != null) { + equals(this) + apply { equals(this); this.equals(this) } + also { it.equals(this) } + } +} + +// TESTCASE NUMBER: 3 +fun T.case_3() { + if (this != null) { + this + this.equals(this) + } +} + +// TESTCASE NUMBER: 4 +fun T?.case_4() { + if (this != null) { + this + this.equals(this) + } +} + +// TESTCASE NUMBER: 5 +fun T?.case_5() { + if (this is Interface1) { + if (this != null) { + this + this.equals(this) + this.itest1() + + equals(this) + itest1() + apply { + this + this + equals(this) + itest1() + this.equals(this) + this.itest1() + } + also { + it + it + it.itest1() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 6 +fun T?.case_6() { + if (this is Interface1?) { + if (this != null) { + this + this.equals(this) + this.itest1() + + equals(this) + itest1() + apply { + this + equals(this) + itest1() + this.equals(this) + this.itest1() + } + also { + it + it.itest1() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 7 +fun T.case_7() { + val x = this + if (x is Interface1?) { + if (x != null) { + x + x.equals(this) + x.itest1() + + x.apply { + this + equals(this) + itest1() + this.equals(this) + this.itest1() + } + x.also { + it + it.itest1() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 8 +fun T.case_8() { + if (this != null) { + if (this is Interface1?) { + this + this.equals(this) + this.itest1() + + equals(this) + itest1() + apply { + this + equals(this) + itest1() + this.equals(this) + this.itest1() + } + also { + it + it.itest1() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 9 +fun T.case_9() { + if (this != null) { + this + this.equals(this) + this.toByte() + + equals(this) + toByte() + apply { + this + equals(this) + toByte() + this.equals(this) + this.toByte() + } + also { + it + it.equals(it) + it.toByte() + } + } +} + +// TESTCASE NUMBER: 10 +fun T.case_10() { + if (this != null) { + this + this.equals(this) + this.toByte() + + equals(this) + toByte() + apply { + this + equals(this) + toByte() + this.equals(this) + this.toByte() + } + also { + it + it.toByte() + it.equals(it) + } + } +} + +// TESTCASE NUMBER: 11 +fun T?.case_11() { + if (this is Interface1?) { + if (this != null) { + this + this.equals(this) + this.itest1() + + equals(this) + itest1() + apply { + this + equals(this) + itest1() + this.equals(this) + this.itest1() + } + also { + it + it.itest1() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 12 +fun T.case_12() where T : Number?, T: Interface1? { + if (this != null) { + this + this.equals(this) + this.itest1() + this.toByte() + + equals(this) + itest1() + apply { + this + equals(this) + itest1() + this.equals(this) + this.itest1() + } + also { + it + it.itest1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 13 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T.case_13() where T : Out<*>?, T: Comparable { + if (this != null) { + this + this.equals(this) + this.get() + this.compareTo(null) + + equals(this) + get() + compareTo(null) + apply { + this + equals(this) + get() + compareTo(null) + this.equals(this) + this.get() + this.compareTo(null) + } + also { + it + it.get() + it.equals(it) + it.compareTo(null) + } + } +} + +/* + * TESTCASE NUMBER: 14 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> T.case_14() { + if (this != null) { + this + this.equals(this) + this.get() + + equals(this) + get() + apply { + this + equals(this) + get() + this.equals(this) + this.get() + } + also { + it + it.get() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 15 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> T.case_15() { + if (this != null) { + this + this.equals(this) + this.itest1() + + equals(this) + itest1() + apply { + this + equals(this) + itest1() + this.equals(this) + this.itest1() + } + also { + it + it.itest1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 16 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> T.case_16() { + if (this != null) { + this + this.equals(this) + this.ip1test1() + + equals(this) + ip1test1() + apply { + this + equals(this) + ip1test1() + this.equals(this) + this.ip1test1() + } + also { + it + it.ip1test1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 17 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> T.case_17() { + if (this != null) { + this + this.equals(this) + this.ip1test1() + + equals(this) + ip1test1() + apply { + this + equals(this) + ip1test1() + this.equals(this) + this.ip1test1() + } + also { + it + it.ip1test1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 18 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> T.case_18() { + val y = this + + if (y != null) { + y + y.equals(y) + y.ip1test1() + + equals(y) + ip1test1() + apply { + this + equals(this) + ip1test1() + this.equals(y) + this.ip1test1() + } + also { + it + it.ip1test1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 19 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> T.case_19() { + if (this != null) { + this + this.equals(this) + this.ip1test1() + + equals(this) + ip1test1() + apply { + this + equals(this) + ip1test1() + this.equals(this) + this.ip1test1() + } + also { + it + it.ip1test1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 20 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T.case_20() where T: InterfaceWithTypeParameter1?, T: InterfaceWithTypeParameter2? { + if (this != null) { + this + this.equals(this) + this.ip1test1() + this.ip1test2() + + equals(this) + ip1test1() + ip1test2() + apply { + this + equals(this) + ip1test1() + ip1test2() + this.equals(this) + this.ip1test1() + this.ip1test2() + } + also { + it + it.equals(it) + it.ip1test1() + it.ip1test2() + } + } +} + +/* + * TESTCASE NUMBER: 21 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T.case_21() where T: InterfaceWithTypeParameter1?, T: InterfaceWithTypeParameter2?, T: InterfaceWithTypeParameter3? { + if (this != null) { + this + this.equals(this) + this.ip1test1() + this.ip1test2() + this.ip1test3() + + equals(this) + ip1test1() + ip1test2() + ip1test3() + apply { + this + equals(this) + ip1test1() + ip1test2() + ip1test3() + this.equals(this) + this.ip1test1() + this.ip1test2() + this.ip1test3() + } + also { + it + it.equals(it) + it.ip1test1() + it.ip1test2() + it.ip1test3() + } + } +} + +/* + * TESTCASE NUMBER: 22 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun >?> T.case_22() { + var y = this + + if (y != null) { + y + y.equals(y) + y.ip1test1() + + equals(y) + ip1test1() + apply { + this + equals(this) + ip1test1() + this.equals(this) + this.ip1test1() + } + also { + it + it.equals(it) + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 23 +fun >?> T.case_23() { + if (this != null) { + this + this.equals(this) + this.ip1test1() + + equals(this) + ip1test1() + apply { + this + equals(this) + ip1test1() + this.equals(this) + this.ip1test1() + } + also { + it + it.equals(it) + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 24 +fun > InterfaceWithTypeParameter1?.case_24() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?"), DEBUG_INFO_SMARTCAST!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?"), DEBUG_INFO_SMARTCAST!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 25 +fun > InterfaceWithTypeParameter1?.case_25() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?"), DEBUG_INFO_SMARTCAST!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?"), DEBUG_INFO_SMARTCAST!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 26 +fun > InterfaceWithTypeParameter1?.case_26() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 27 +fun > InterfaceWithTypeParameter1?.case_27() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 28 +fun > InterfaceWithTypeParameter1?.case_28() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 29 +fun > InterfaceWithTypeParameter1?.case_29() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 30 +fun > InterfaceWithTypeParameter1?.case_30() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 31 +fun > InterfaceWithTypeParameter1?.case_31() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 32 +fun Map?.case_32() { + if (this != null) { + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.equals(this) + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.isEmpty() + + equals(this) + isEmpty() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 33 +fun InterfaceWithFiveTypeParameters1?.case_33() { + if (this != null) { + & InterfaceWithFiveTypeParameters1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1?")!>this + & InterfaceWithFiveTypeParameters1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1?")!>this.equals(this) + & InterfaceWithFiveTypeParameters1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1?")!>this.itest() + + equals(this) + itest() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this + equals(this) + itest() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this.itest() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.itest() + } + } +} + +// TESTCASE NUMBER: 34 +fun InterfaceWithTypeParameter1?.case_34() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 35 +fun InterfaceWithTypeParameter1?.case_35() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 36 +fun InterfaceWithTypeParameter1?.case_36() { + if (this != null) { + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.equals(this) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1?")!>this.ip1test1() + + equals(this) + ip1test1() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 37 +fun Map?.case_37() { + if (this != null) { + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.equals(this) + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.isEmpty() + + equals(this) + isEmpty() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 38 +fun Map<*, out T>?.case_38() { + if (this != null) { + & kotlin.collections.Map<*, out T>?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map<*, out T>?")!>this + & kotlin.collections.Map<*, out T>?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map<*, out T>?")!>this.equals(this) + & kotlin.collections.Map<*, out T>?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map<*, out T>?")!>this.isEmpty() + + equals(this) + isEmpty() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 39 +fun InterfaceWithTwoTypeParameters?.case_39() { + if (this != null) { + & InterfaceWithTwoTypeParameters?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters?")!>this + & InterfaceWithTwoTypeParameters?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters?")!>this.equals(this) + + equals(this) + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters")!>this + equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters")!>this.equals(this) + } + also { + ")!>it + ")!>it.equals(it) + } + } +} + +// TESTCASE NUMBER: 40 +fun InterfaceWithTwoTypeParameters?.case_40() { + if (this != null) { + & InterfaceWithTwoTypeParameters?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters?")!>this + & InterfaceWithTwoTypeParameters?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters?")!>this.equals(this) + + equals(this) + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters")!>this + equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters")!>this.equals(this) + } + also { + ")!>it + ")!>it.equals(it) + } + } +} + +// TESTCASE NUMBER: 41 +fun Mapout T>?.case_41() { + if (this != null) { + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.equals(this) + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.isEmpty() + + equals(this) + isEmpty() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 42 +fun Mapout T>?.case_42() { + if (this != null) { + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.equals(this) + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.isEmpty() + + equals(this) + isEmpty() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 43 +fun Map?.case_43() { + if (this != null) { + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.equals(this) + & kotlin.collections.Map?"), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map?")!>this.isEmpty() + + equals(this) + isEmpty() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 44 +fun InterfaceWithFiveTypeParameters1?.case_44() { + if (this != null) { + & InterfaceWithFiveTypeParameters1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1?")!>this + & InterfaceWithFiveTypeParameters1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1?")!>this.equals(this) + & InterfaceWithFiveTypeParameters1?"), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1?")!>this.itest() + + equals(this) + itest() + apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this + equals(this) + itest() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this.equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this.itest() + } + also { + ")!>it + ")!>it.equals(it) + ")!>it.itest() + } + } +} + +// TESTCASE NUMBER: 45 +fun T.case_45() where T : Number?, T: Comparable? { + if (this != null) { + this + this.equals(this) + this.toByte() + this.compareTo(this) + + equals(this) + toByte() + compareTo(this) + apply { + this + equals(this) + compareTo(this) + toByte() + this.equals(this) + this.compareTo(this) + this.toByte() + } + also { + it + it.equals(it) + it.compareTo(it) + it.toByte() + } + } +} + +// TESTCASE NUMBER: 46 +fun T.case_46() where T : CharSequence?, T: Comparable?, T: Iterable<*>? { + if (this != null) { + this + this.equals(this) + this.compareTo(this) + this.get(0) + this.iterator() + + equals(this) + compareTo(this) + get(0) + iterator() + apply { + this + equals(this) + compareTo(this) + get(0) + iterator() + this.equals(this) + this.compareTo(this) + this.get(0) + this.iterator() + } + also { + it + it.equals(it) + it.compareTo(it) + it.get(0) + it.iterator() + } + } +} + +/* + * TESTCASE NUMBER: 47 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T?.case_47() where T : Inv, T: Comparable<*>?, T: InterfaceWithTypeParameter1? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + + this.compareTo(return) + compareTo(return) + + apply { + compareTo(return) + this.compareTo(return) + } + + also { + it.compareTo(return) + } + } +} + +/* + * TESTCASE NUMBER: 48 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T?.case_48() where T : Inv, T: InterfaceWithTypeParameter1? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 49 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T?.case_49() where T : Inv, T: InterfaceWithTypeParameter1? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 50 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T?.case_50() where T : Inv, T: InterfaceWithTypeParameter1? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 51 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T?.case_51() where T : Inv, T: InterfaceWithTypeParameter1? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 52 +fun T?.case_52() where T : Inv, T: InterfaceWithTypeParameter1? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 53 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T?.case_53() where T : Inv, T: InterfaceWithTypeParameter1<*>? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 54 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T?.case_54() where T : Inv<*>, T: InterfaceWithTypeParameter1? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 55 +fun T?.case_55() where T : Inv<*>, T: InterfaceWithTypeParameter1? { + if (this != null) { + this + this.equals(this) + this.get() + this.ip1test1() + + equals(this) + get() + ip1test1() + apply { + this + equals(this) + get() + ip1test1() + this.equals(this) + this.get() + this.ip1test1() + } + also { + it + it.equals(it) + it.get() + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 56 +fun T.case_56() where T : Number?, T: Interface1? { + if (this != null) { + this + this.equals(this) + this.itest() + this.toByte() + + equals(this) + itest() + toByte() + apply { + this + equals(this) + itest() + toByte() + this.equals(this) + this.itest() + this.toByte() + } + also { + it + it.equals(it) + it.itest() + it.toByte() + } + } +} + +/* + * TESTCASE NUMBER: 57 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T.case_57() where T : Out<*>?, T: Comparable { + if (this != null) { + this + this.equals(this) + this.get() + this.compareTo(null) + + equals(this) + get() + compareTo(null) + apply { + this + equals(this) + get() + compareTo(null) + this.equals(this) + this.get() + this.compareTo(null) + } + also { + it + it.equals(it) + it.get() + it.compareTo(null) + } + } +} + +// TESTCASE NUMBER: 58 +fun >>>>>>>>>?> T.case_59() { + if (this != null) { + this + this.equals(this) + this.ip1test1() + + equals(this) + ip1test1() + apply { + this + equals(this) + ip1test1() + this.equals(this) + this.ip1test1() + } + also { + it + it.equals(it) + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 59 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T.case_59() where T: InterfaceWithFiveTypeParameters1?, T: InterfaceWithFiveTypeParameters2?, T: InterfaceWithFiveTypeParameters3? { + if (this != null) { + this + this.equals(this) + this.itest1() + this.itest2() + this.itest3() + + equals(this) + itest1() + itest2() + itest3() + apply { + this + equals(this) + itest1() + itest2() + itest3() + this.equals(this) + this.itest1() + this.itest2() + this.itest3() + } + also { + it + it.equals(it) + it.itest1() + it.itest2() + it.itest3() + } + } +} + +/* + * TESTCASE NUMBER: 60 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> T.case_60() { + if (this != null) { + this + this.equals(this) + this.ip1test1() + + equals(this) + ip1test1() + apply { + this + equals(this) + ip1test1() + this.equals(this) + this.ip1test1() + } + also { + it + it.equals(it) + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 61 +interface Case61_1: InterfaceWithTypeParameter1, Case61_2 { fun test1() } +interface Case61_2: InterfaceWithTypeParameter1 { fun test2() } + +class Case61_3: InterfaceWithTypeParameter1, Case61_1, Case61_2 { + override fun test1() {} + override fun test2() {} + fun test4() {} +} + +fun T.case_61() where T : InterfaceWithTypeParameter1?, T: Case61_3?, T: Case61_1?, T: Case61_2? { + if (this != null) { + this.test1() + this.test2() + this.ip1test1() + this.test4() + + test1() + test2() + ip1test1() + test4() + apply { + this + test1() + test2() + ip1test1() + test4() + this.test1() + this.test2() + this.ip1test1() + this.test4() + } + also { + it + it.test1() + it.test2() + it.ip1test1() + it.test4() + } + } +} + +// TESTCASE NUMBER: 62 +fun Nothing?.case_62() { + if (this != null) { + this + this.equals(this) + + equals(this) + apply { + this + equals(this) + this.equals(this) + } + also { + it + it.equals(this) + } + } +} + +// TESTCASE NUMBER: 63 +fun Nothing.case_63() { + if (this != null) { + this + this.hashCode() + + hashCode() + apply { + this + hashCode() + this.hashCode() + } + also { + it + it.hashCode() + } + } +} + +/* + * TESTCASE NUMBER: 64 + * UNEXPECTED BEHAVIOUR + */ +fun T.case_64() { + if (this != null) { + this + this.hashCode() + + hashCode() + apply { + this + hashCode() + this.hashCode() + } + also { + it + it.hashCode() + } + } +} + +/* + * TESTCASE NUMBER: 65 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun T.case_65() { + if (this is Interface1?) { + if (this is Interface2?) { + if (this != null) { + this + this.equals(x) + apply { + this + this.equals(this) + } + also { + it + it.equals(it) + } + } + } + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.13.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.13.kt new file mode 100644 index 00000000000..da81b2d6e9f --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.13.kt @@ -0,0 +1,1662 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 13 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) on generic function parameters using if expression. + * HELPERS: classes, interfaces + */ + +// TESTCASE NUMBER: 1 +fun case_1(x: T) { + var y = null + + if (y != x) { + x + x.equals(x) + x.apply { equals(x); x.equals(x) } + x.also { it.equals(x) } + } +} + +// TESTCASE NUMBER: 2 +fun case_2(x: T?, y: Nothing?) { + if (y != x) { + x + x.equals(x) + x.apply { equals(x); x.equals(x) } + x.also { it.equals(x) } + } +} + +// TESTCASE NUMBER: 3 +fun case_3(x: T) { + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 4 +fun case_4(x: T?) { + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 5 +fun case_5(x: T?) { + if (x is Interface1) { + if (x != null) { + x + x.equals(x) + x.itest() + + x.equals(x) + x.itest() + x.apply { + this + this + equals(this) + itest() + this.equals(x) + this.itest() + } + x.also { + it + it + it.itest() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 6 +fun case_6(x: T?) { + if (x is Interface1?) { + if (x != null) { + x + x.equals(x) + x.itest() + + x.equals(x) + x.itest() + x.apply { + this + equals(this) + itest() + this.equals(x) + this.itest() + } + x.also { + it + it.itest() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 7 +fun case_7(y: T) { + val x = y + if (x is Interface1?) { + if (x != null) { + x + x.equals(x) + x.itest() + + x.apply { + this + equals(this) + itest() + this.equals(x) + this.itest() + } + x.also { + it + it.itest() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: T) { + if (x != null) { + if (x is Interface1?) { + x + x.equals(x) + x.itest() + + x.equals(x) + x.itest() + x.apply { + this + equals(this) + itest() + this.equals(x) + this.itest() + } + x.also { + it + it.itest() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 9 +fun case_9(x: T) { + if (x != null) { + x + x.equals(x) + x.toByte() + + x.equals(x) + x.toByte() + x.apply { + this + equals(this) + x.toByte() + this.equals(x) + this.toByte() + } + x.also { + it + it.equals(it) + it.toByte() + } + } +} + +// TESTCASE NUMBER: 10 +fun case_10(x: T) { + if (x != null) { + x + x.equals(x) + x.toByte() + + x.equals(x) + x.toByte() + x.apply { + this + equals(this) + toByte() + this.equals(x) + this.toByte() + } + x.also { + it + it.toByte() + it.equals(it) + } + } +} + +// TESTCASE NUMBER: 11 +fun case_11(x: T?) { + if (x is Interface1?) { + if (x != null) { + x + x.equals(x) + x.itest() + + x.equals(x) + x.itest() + x.apply { + this + equals(this) + itest() + this.equals(x) + this.itest() + } + x.also { + it + it.itest() + it.equals(it) + } + } + } +} + +// TESTCASE NUMBER: 12 +fun case_12(x: T) where T : Number?, T: Interface1? { + if (x != null) { + x + x.equals(x) + x.itest() + x.toByte() + + x.equals(x) + x.itest() + x.apply { + this + equals(this) + itest() + this.equals(x) + this.itest() + } + x.also { + it + it.itest() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 13 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_13(x: T) where T : Out<*>?, T: Comparable { + if (x != null) { + x + x.equals(x) + x.get() + x.compareTo(null) + + x.equals(x) + x.get() + x.compareTo(null) + x.apply { + this + equals(this) + get() + compareTo(null) + this.equals(x) + this.get() + this.compareTo(null) + } + x.also { + it + it.get() + it.equals(it) + it.compareTo(null) + } + } +} + +/* + * TESTCASE NUMBER: 14 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> case_14(x: T) { + if (x != null) { + x + x.equals(x) + x.get() + + x.equals(x) + x.get() + x.apply { + this + equals(this) + get() + this.equals(x) + this.get() + } + x.also { + it + it.get() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 15 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> case_15(x: T) { + if (x != null) { + x + x.equals(x) + x.itest() + + x.equals(x) + x.itest() + x.apply { + this + equals(this) + itest() + this.equals(x) + this.itest() + } + x.also { + it + it.itest() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 16 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> case_16(x: T) { + if (x != null) { + x + x.equals(x) + x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + this + equals(this) + ip1test1() + this.equals(x) + this.ip1test1() + } + x.also { + it + it.ip1test1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 17 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> case_17(x: T) { + if (x != null) { + x + x.equals(x) + x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + this + equals(this) + ip1test1() + this.equals(x) + this.ip1test1() + } + x.also { + it + it.ip1test1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 18 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> case_18(x: T) { + val y = x + + if (y != null) { + y + y.equals(y) + y.ip1test1() + + x.equals(y) + x.ip1test1() + x.apply { + this + equals(this) + ip1test1() + this.equals(y) + this.ip1test1() + } + x.also { + it + it.ip1test1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 19 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> case_19(x: T) { + if (x != null) { + x + x.equals(x) + x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + this + equals(this) + ip1test1() + this.equals(x) + this.ip1test1() + } + x.also { + it + it.ip1test1() + it.equals(it) + } + } +} + +/* + * TESTCASE NUMBER: 20 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_20(x: T) where T: InterfaceWithTypeParameter1?, T: InterfaceWithTypeParameter2? { + if (x != null) { + x + x.equals(x) + x.ip1test1() + x.ip1test2() + + x.equals(x) + x.ip1test1() + x.ip1test2() + x.apply { + this + equals(this) + ip1test1() + ip1test2() + this.equals(x) + this.ip1test1() + this.ip1test2() + } + x.also { + it + it.equals(it) + it.ip1test1() + it.ip1test2() + } + } +} + +/* + * TESTCASE NUMBER: 21 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_21(x: T) where T: InterfaceWithTypeParameter1?, T: InterfaceWithTypeParameter2?, T: InterfaceWithTypeParameter3? { + if (x != null) { + x + x.equals(x) + x.ip1test1() + x.ip1test2() + x.ip1test3() + + x.equals(x) + x.ip1test1() + x.ip1test2() + x.ip1test3() + x.apply { + this + equals(this) + ip1test1() + ip1test2() + ip1test3() + this.equals(x) + this.ip1test1() + this.ip1test2() + this.ip1test3() + } + x.also { + it + it.equals(it) + it.ip1test1() + it.ip1test2() + it.ip1test3() + } + } +} + +/* + * TESTCASE NUMBER: 22 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun >?> case_22(x: T) { + var y = x + + if (y != null) { + y + y.equals(y) + y.ip1test1() + + x.equals(y) + x.ip1test1() + x.apply { + this + equals(this) + ip1test1() + this.equals(x) + this.ip1test1() + } + x.also { + it + it.equals(it) + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 23 +fun >?> case_23(x: T) { + if (x != null) { + x + x.equals(x) + x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + this + equals(this) + ip1test1() + this.equals(x) + this.ip1test1() + } + x.also { + it + it.equals(it) + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 24 +fun > case_24(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_SMARTCAST!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 25 +fun > case_25(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + & InterfaceWithTypeParameter1?"), DEBUG_INFO_SMARTCAST!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 26 +fun > case_26(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 27 +fun > case_27(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 28 +fun > case_28(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 29 +fun > case_29(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 30 +fun > case_30(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 31 +fun > case_31(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 32 +fun case_32(x: Map?) { + if (x != null) { + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?")!>x.equals(x) + & kotlin.collections.Map?")!>x.isEmpty() + + x.equals(x) + x.isEmpty() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 33 +fun case_33(x: InterfaceWithFiveTypeParameters1?) { + if (x != null) { + & InterfaceWithFiveTypeParameters1?")!>x + & InterfaceWithFiveTypeParameters1?")!>x.equals(x) + & InterfaceWithFiveTypeParameters1?")!>x.itest() + + x.equals(x) + x.itest() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this + equals(this) + itest() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this.itest() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.itest() + } + } +} + +// TESTCASE NUMBER: 34 +fun case_34(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 35 +fun case_35(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 36 +fun case_36(x: InterfaceWithTypeParameter1?) { + if (x != null) { + & InterfaceWithTypeParameter1?")!>x + & InterfaceWithTypeParameter1?")!>x.equals(x) + & InterfaceWithTypeParameter1?")!>x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this + equals(this) + ip1test1() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTypeParameter1")!>this.ip1test1() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 37 +fun case_37(x: Map?) { + if (x != null) { + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?")!>x.equals(x) + & kotlin.collections.Map?")!>x.isEmpty() + + x.equals(x) + x.isEmpty() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 38 +fun case_38(x: Map<*, out T>?) { + if (x != null) { + & kotlin.collections.Map<*, out T>?")!>x + & kotlin.collections.Map<*, out T>?")!>x.equals(x) + & kotlin.collections.Map<*, out T>?")!>x.isEmpty() + + x.equals(x) + x.isEmpty() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 39 +fun case_39(x: InterfaceWithTwoTypeParameters?) { + if (x != null) { + & InterfaceWithTwoTypeParameters?")!>x + & InterfaceWithTwoTypeParameters?")!>x.equals(x) + + x.equals(x) + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters")!>this + equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters")!>this.equals(x) + } + x.also { + ")!>it + ")!>it.equals(it) + } + } +} + +// TESTCASE NUMBER: 40 +fun case_40(x: InterfaceWithTwoTypeParameters?) { + if (x != null) { + & InterfaceWithTwoTypeParameters?")!>x + & InterfaceWithTwoTypeParameters?")!>x.equals(x) + + x.equals(x) + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters")!>this + equals(this) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithTwoTypeParameters")!>this.equals(x) + } + x.also { + ")!>it + ")!>it.equals(it) + } + } +} + +// TESTCASE NUMBER: 41 +fun case_41(x: Mapout T>?) { + if (x != null) { + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?")!>x.equals(x) + & kotlin.collections.Map?")!>x.isEmpty() + + x.equals(x) + x.isEmpty() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 42 +fun case_42(x: Mapout T>?) { + if (x != null) { + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?")!>x.equals(x) + & kotlin.collections.Map?")!>x.isEmpty() + + x.equals(x) + x.isEmpty() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 43 +fun case_43(x: Map?) { + if (x != null) { + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?")!>x.equals(x) + & kotlin.collections.Map?")!>x.isEmpty() + + x.equals(x) + x.isEmpty() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this + equals(this) + isEmpty() + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Map")!>this.isEmpty() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.isEmpty() + } + } +} + +// TESTCASE NUMBER: 44 +fun case_44(x: InterfaceWithFiveTypeParameters1?) { + if (x != null) { + & InterfaceWithFiveTypeParameters1?")!>x + & InterfaceWithFiveTypeParameters1?")!>x.equals(x) + & InterfaceWithFiveTypeParameters1?")!>x.itest() + + x.equals(x) + x.itest() + x.apply { + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this + equals(this) + itest() + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this.equals(x) + "), DEBUG_INFO_EXPRESSION_TYPE("InterfaceWithFiveTypeParameters1")!>this.itest() + } + x.also { + ")!>it + ")!>it.equals(it) + ")!>it.itest() + } + } +} + +// TESTCASE NUMBER: 45 +fun case_45(x: T) where T : Number?, T: Comparable? { + if (x != null) { + x + x.equals(x) + x.toByte() + x.compareTo(x) + + x.equals(x) + x.toByte() + x.compareTo(x) + x.apply { + this + equals(this) + compareTo(this) + x.toByte() + this.equals(x) + this.compareTo(x) + this.toByte() + } + x.also { + it + it.equals(it) + it.compareTo(it) + it.toByte() + } + } +} + +// TESTCASE NUMBER: 46 +fun case_46(x: T) where T : CharSequence?, T: Comparable?, T: Iterable<*>? { + if (x != null) { + x + x.equals(x) + x.compareTo(x) + x.get(0) + x.iterator() + + x.equals(x) + x.compareTo(x) + x.get(0) + x.iterator() + x.apply { + this + equals(this) + compareTo(this) + get(0) + iterator() + this.equals(x) + this.compareTo(x) + this.get(0) + this.iterator() + } + x.also { + it + it.equals(it) + it.compareTo(it) + it.get(0) + it.iterator() + } + } +} + +/* + * TESTCASE NUMBER: 47 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_47(x: T?) where T : Inv, T: Comparable<*>?, T: InterfaceWithTypeParameter1? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + + x.compareTo(return) + x.compareTo(return) + + x.apply { + compareTo(return) + this.compareTo(return) + } + + x.also { + it.compareTo(return) + } + } +} + +/* + * TESTCASE NUMBER: 48 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_48(x: T?) where T : Inv, T: InterfaceWithTypeParameter1? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 49 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_49(x: T?) where T : Inv, T: InterfaceWithTypeParameter1? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 50 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_50(x: T?) where T : Inv, T: InterfaceWithTypeParameter1? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 51 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_51(x: T?) where T : Inv, T: InterfaceWithTypeParameter1? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 52 +fun case_52(x: T?) where T : Inv, T: InterfaceWithTypeParameter1? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 53 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_53(x: T?) where T : Inv, T: InterfaceWithTypeParameter1<*>? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 54 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_54(x: T?) where T : Inv<*>, T: InterfaceWithTypeParameter1? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 55 +fun case_55(x: T?) where T : Inv<*>, T: InterfaceWithTypeParameter1? { + if (x != null) { + x + x.equals(x) + x.test() + x.ip1test1() + + x.equals(x) + x.test() + x.ip1test1() + x.apply { + this + equals(this) + test() + ip1test1() + this.equals(x) + this.test() + this.ip1test1() + } + x.also { + it + it.equals(it) + it.test() + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 56 +fun case_56(x: T) where T : Number?, T: Interface1? { + if (x != null) { + x + x.equals(x) + x.itest() + x.toByte() + + x.equals(x) + x.itest() + x.toByte() + x.apply { + this + equals(this) + itest() + x.toByte() + this.equals(x) + this.itest() + this.toByte() + } + x.also { + it + it.equals(it) + it.itest() + it.toByte() + } + } +} + +/* + * TESTCASE NUMBER: 57 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_57(x: T) where T : Out<*>?, T: Comparable { + if (x != null) { + x + x.equals(x) + x.get() + x.compareTo(null) + + x.equals(x) + x.get() + x.compareTo(null) + x.apply { + this + equals(this) + get() + compareTo(null) + this.equals(x) + this.get() + this.compareTo(null) + } + x.also { + it + it.equals(it) + it.get() + it.compareTo(null) + } + } +} + +// TESTCASE NUMBER: 58 +fun >>>>>>>>>?> case_59(x: T) { + if (x != null) { + x + x.equals(x) + x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + this + equals(this) + ip1test1() + this.equals(x) + this.ip1test1() + } + x.also { + it + it.equals(it) + it.ip1test1() + } + } +} + +/* + * TESTCASE NUMBER: 59 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_59(x: T) where T: InterfaceWithFiveTypeParameters1?, T: InterfaceWithFiveTypeParameters2?, T: InterfaceWithFiveTypeParameters3? { + if (x != null) { + x + x.equals(x) + x.itest1() + x.itest2() + x.itest3() + + x.equals(x) + x.itest1() + x.itest2() + x.itest3() + x.apply { + this + equals(this) + itest1() + itest2() + itest3() + this.equals(x) + this.itest1() + this.itest2() + this.itest3() + } + x.also { + it + it.equals(it) + it.itest1() + it.itest2() + it.itest3() + } + } +} + +/* + * TESTCASE NUMBER: 60 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun ?> case_60(x: T) { + if (x != null) { + x + x.equals(x) + x.ip1test1() + + x.equals(x) + x.ip1test1() + x.apply { + this + equals(this) + ip1test1() + this.equals(x) + this.ip1test1() + } + x.also { + it + it.equals(it) + it.ip1test1() + } + } +} + +// TESTCASE NUMBER: 61 +interface Case61_1: InterfaceWithTypeParameter1, Case61_2 { fun test1() } +interface Case61_2: InterfaceWithTypeParameter1 { fun test2() } + +class Case61_3: InterfaceWithTypeParameter1, Case61_1, Case61_2 { + override fun test1() {} + override fun test2() {} + fun test4() {} +} + +fun T.case_61(x: T) where T : InterfaceWithTypeParameter1?, T: Case61_3?, T: Case61_1?, T: Case61_2? { + if (x != null) { + x.ip1test1() + x.test2() + x.ip1test1() + x.test4() + + x.ip1test1() + x.test2() + x.ip1test1() + x.test4() + x.apply { + this + ip1test1() + test2() + ip1test1() + test4() + this.ip1test1() + this.test2() + this.ip1test1() + this.test4() + } + x.also { + it + it.ip1test1() + it.test2() + it.ip1test1() + it.test4() + } + } +} + +/* + * TESTCASE NUMBER: 62 + * UNEXPECTED BEHAVIOUR + */ +fun case_62(x: T) { + if (x != null) { + x + x.hashCode() + + x.hashCode() + x.apply { + this + hashCode() + this.hashCode() + } + x.also { + it + it.hashCode() + } + } +} \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.14.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.14.kt new file mode 100644 index 00000000000..fa859ba71d1 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.14.kt @@ -0,0 +1,67 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 14 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) using if expression and vararg. + */ + +// TESTCASE NUMBER: 1 +fun case_1(vararg x: Int?) { + if (x != null) { + ")!>x + x[0] + } +} + +// TESTCASE NUMBER: 2 +fun case_2(vararg x: Int?) { + x[0].apply { + if (this != null) { + this + this.inv() + } + } + + x[0].also { + if (it != null) { + it + it.inv() + } + } +} + +// TESTCASE NUMBER: 3 +fun case_3(vararg x: T?) { + if (x != null) { + ")!>x + x[0] + } +} + +// TESTCASE NUMBER: 4 +fun case_4(vararg x: T?) { + x[0].apply { + if (this != null) { + this + this.toByte() + } + } + + x[0].also { + if (it != null) { + it + it.toByte() + } + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.15.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.15.kt new file mode 100644 index 00000000000..847347695cd --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.15.kt @@ -0,0 +1,195 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 15 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) on big types using if expression. + * NOTE: performance test + * HELPERS: classes, interfaces, functions + */ + +// TESTCASE NUMBER: 1 +open class Case1_1 : InterfaceWithTypeParameter1 +open class Case1_2 : InterfaceWithTypeParameter1 + +fun case_1() { + val a = select(Case1_1(), Case1_2(), null) + + if (a != null) { + >>>>> & InterfaceWithTypeParameter1>>>>>?")!>a + val b = >>>>> & InterfaceWithTypeParameter1>>>>>?")!>a.ip1test1() + if (b != null) { + >>>> & InterfaceWithTypeParameter1>>>>?")!>b + val c = >>>> & InterfaceWithTypeParameter1>>>>?")!>b.ip1test1() + if (c != null) { + >>> & InterfaceWithTypeParameter1>>>?")!>c + val d = >>> & InterfaceWithTypeParameter1>>>?")!>c.ip1test1() + if (d != null) { + >> & InterfaceWithTypeParameter1>>?")!>d + val e = >> & InterfaceWithTypeParameter1>>?")!>d.ip1test1() + if (e != null) { + > & InterfaceWithTypeParameter1>?")!>e + val f = > & InterfaceWithTypeParameter1>?")!>e.ip1test1() + if (f != null) { + & InterfaceWithTypeParameter1<*>?")!>f + val g = & InterfaceWithTypeParameter1<*>?")!>f.ip1test1() + if (g != null) { + g.equals(null) + } + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 2 +class Case2_1 : Interface1, InterfaceWithTypeParameter1 +class Case2_2 : Interface1, InterfaceWithTypeParameter1 + +fun case_2() { + val x = select(Case2_1(), Case2_2(), null) + + if (x != null) { + }>}>}>}>} & {Interface1? & InterfaceWithTypeParameter1}>}>}>}>?}")!>x + }>}>}>}>} & {Interface1? & InterfaceWithTypeParameter1}>}>}>}>?}")!>x.ip1test1() + } +} + +// TESTCASE NUMBER: 3 +class Case3_1 : Interface1, InterfaceWithTypeParameter1, InterfaceWithTypeParameter2 +class Case3_2 : Interface1, InterfaceWithTypeParameter1, InterfaceWithTypeParameter2 + +fun case_3() { + val x = select(Case3_1(), Case3_2(), null) + + if (x != null) { + & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>} & {Interface1? & InterfaceWithTypeParameter1 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>? & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>?}")!>x + & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>} & {Interface1? & InterfaceWithTypeParameter1 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>? & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>?}")!>x.ip1test1() + & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>} & {Interface1? & InterfaceWithTypeParameter1 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>? & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>?}")!>x.ip1test2() + } +} + +// TESTCASE NUMBER: 4 +class Case4_1 : InterfaceWithTypeParameter1, InterfaceWithTypeParameter2 +class Case4_2 : InterfaceWithTypeParameter1, InterfaceWithTypeParameter2 + +fun case_4() { + val x = select(Case4_1(), Case4_2(), null) + + if (x != null) { + & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>} & {InterfaceWithTypeParameter1 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>? & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>?}")!>x + & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>} & {InterfaceWithTypeParameter1 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>? & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>?}")!>x.ip1test1() + & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>} & {InterfaceWithTypeParameter1 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>? & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>}>}>}>?}")!>x.ip1test2() + } +} + +// TESTCASE NUMBER: 5 +class Case5_1 : InterfaceWithTypeParameter1>, InterfaceWithTypeParameter2> +class Case5_2 : InterfaceWithTypeParameter2>, InterfaceWithTypeParameter1> + +fun case_5() { + val x = select(Case5_1(), Case5_2(), null) + + if (x != null) { + > & InterfaceWithTypeParameter2>} & {InterfaceWithTypeParameter1> & InterfaceWithTypeParameter2>}?")!>x + > & InterfaceWithTypeParameter2>} & {InterfaceWithTypeParameter1> & InterfaceWithTypeParameter2>}?"), DEBUG_INFO_SMARTCAST!>x.ip1test1() + > & InterfaceWithTypeParameter2>} & {InterfaceWithTypeParameter1> & InterfaceWithTypeParameter2>}?"), DEBUG_INFO_SMARTCAST!>x.ip1test2() + } +} + +// TESTCASE NUMBER: 6 +class Case6_1 : InterfaceWithTypeParameter1>, InterfaceWithTypeParameter2>> +class Case6_2 : InterfaceWithTypeParameter2>>, InterfaceWithTypeParameter1> + +fun case_6() { + val x = select(Case6_1(), Case6_2(), null) + + if (x != null) { + & Number}>> & InterfaceWithTypeParameter2 & Number}>> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>>}>>} & {InterfaceWithTypeParameter1 & Number}>>? & InterfaceWithTypeParameter2 & Number}>> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>>}>>?}")!>x + & Number}>> & InterfaceWithTypeParameter2 & Number}>> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>>}>>} & {InterfaceWithTypeParameter1 & Number}>>? & InterfaceWithTypeParameter2 & Number}>> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>>}>>?}")!>x.ip1test1() + & Number}>> & InterfaceWithTypeParameter2 & Number}>> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>>}>>} & {InterfaceWithTypeParameter1 & Number}>>? & InterfaceWithTypeParameter2 & Number}>> & InterfaceWithTypeParameter2 & InterfaceWithTypeParameter2}>>}>>?}")!>x.ip1test2() + } +} + +// TESTCASE NUMBER: 7 +open class Case7_1 : InterfaceWithTwoTypeParameters, Inv> +open class Case7_2 : InterfaceWithTwoTypeParameters, Inv> + +fun case_7() { + val x = select(Case7_1(), Case7_2(), null) + + if (x != null) { + & java.io.Serializable}>, out Inv & java.io.Serializable}>> & InterfaceWithTwoTypeParameters & java.io.Serializable}>, out Inv & java.io.Serializable}>>?")!>x + & java.io.Serializable}>, out Inv & java.io.Serializable}>> & InterfaceWithTwoTypeParameters & java.io.Serializable}>, out Inv & java.io.Serializable}>>?")!>x.ip2test() + } +} + +// TESTCASE NUMBER: 8 +open class Case8_1 : ClassWithTwoTypeParameters, K>() +open class Case8_2 : ClassWithTwoTypeParameters, T>() + +fun case_8() { + val x = select(Case8_1(), Case8_2(), null) + + if (x != null) { + & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>, out {Comparable<{Char & Float}> & java.io.Serializable}> & ClassWithTwoTypeParameters & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>, out {Comparable<{Char & Float}> & java.io.Serializable}>?")!>x + & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>, out {Comparable<{Char & Float}> & java.io.Serializable}> & ClassWithTwoTypeParameters & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>, out {Comparable<{Char & Float}> & java.io.Serializable}>?")!>x.test1() + val y = & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>, out {Comparable<{Char & Float}> & java.io.Serializable}> & ClassWithTwoTypeParameters & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>, out {Comparable<{Char & Float}> & java.io.Serializable}>?")!>x.test2() + if (y != null) { + & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}> & ClassWithTwoTypeParameters & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>?")!>y + & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}> & ClassWithTwoTypeParameters & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>?")!>y.test1() + val z = & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}> & ClassWithTwoTypeParameters & java.io.Serializable}, out {Comparable<{Char & Float}> & java.io.Serializable}>?")!>y.test2() + if (z != null) { + & java.io.Serializable} & {Comparable<{Int & String}> & java.io.Serializable}?")!>z + & java.io.Serializable} & {Comparable<{Int & String}> & java.io.Serializable}?"), DEBUG_INFO_SMARTCAST!>z.equals(z) + } + } + } +} + +// TESTCASE NUMBER: 9 +open class Case9_1 : ClassWithTwoTypeParameters, Case9_2>() +open class Case9_2 : ClassWithTwoTypeParameters, Case9_1>() + +fun case_9() { + val x = select(Case9_1(), Case9_2(), null) + + if (x != null) { + , out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>> & ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>>?")!>x + , out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>> & ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>>?")!>x.test1() + val y = x.test2() + if (y != null) { + , out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>> & ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>?")!>y + val z = , out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>> & ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>>?")!>y.test2() + if (z != null) { + , out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>> & ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>?")!>z + , out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>> & ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>, out ClassWithTwoTypeParameters, out ClassWithTwoTypeParameters<*, *>>>>>?")!>z.equals(z) + } + } + } +} + +// TESTCASE NUMBER: 10 +open class Case10_1 : Interface1, InterfaceWithOutParameter +open class Case10_2 : Interface1, InterfaceWithOutParameter + +fun case_10() = run { + val x = select(object : Case10_1() {}, object : Case10_2() {}, null) + + if (x != null) { + }>}>}>}>} & {Interface1? & InterfaceWithOutParameter<{Interface1 & InterfaceWithOutParameter<{Interface1 & InterfaceWithOutParameter<{Interface1 & InterfaceWithOutParameter<{Interface1 & InterfaceWithOutParameter}>}>}>}>?}")!>x + }>}>}>}>} & {Interface1? & InterfaceWithOutParameter<{Interface1 & InterfaceWithOutParameter<{Interface1 & InterfaceWithOutParameter<{Interface1 & InterfaceWithOutParameter<{Interface1 & InterfaceWithOutParameter}>}>}>}>?}"), DEBUG_INFO_SMARTCAST!>x.equals(x) + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.16.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.16.kt new file mode 100644 index 00000000000..6b7f70465bc --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.16.kt @@ -0,0 +1,405 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION, -NAME_SHADOWING, -UNUSED_VARIABLE +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 16 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality with `null` and `return` after it) using if expression. + * UNSPECIFIED BEHAVIOR + * HELPERS: objects, properties, classes + */ + +// TESTCASE NUMBER: 1 +fun case_1(x: Int?) { + if (x == null) return + x + x.inv() +} + +// TESTCASE NUMBER: 2 +fun case_2(x: Unit?) { + if (x === null) return + x + x.equals(x) +} + +// TESTCASE NUMBER: 3 +fun case_3(x: Nothing?) { + if (x != null) else return + x + x.equals(x) +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Number?) { + if (x !== null) else { return } + x + x.equals(x) +} + +// TESTCASE NUMBER: 5 +fun case_5(x: Char?, y: Nothing?) { + if (x != y) else return + x + x.equals(x) +} + +// TESTCASE NUMBER: 6 +fun case_6(x: Object?) { + if (x !== implicitNullableNothingProperty) else { return } + x + x.equals(x) +} + +// TESTCASE NUMBER: 7 +fun case_7(x: Class?) { + if (x === implicitNullableNothingProperty || false || false || false) { return } + x + x.equals(x) +} + +// TESTCASE NUMBER: 8 +fun case_8(x: Int?) { + if (false || false || false || x == nullableNothingProperty) return + x + x.inv() +} + +// TESTCASE NUMBER: 9 +fun case_9(x: String?) { + if (x != implicitNullableNothingProperty && true && true && true) else { return } + x + x.equals(x) +} + +// TESTCASE NUMBER: 10 +fun case_10(x: Float?) { + if (true && true && true && x !== null) else return + x + x.equals(x) +} + +// TESTCASE NUMBER: 11 +fun case_11(x: Out<*>?) { + if (x == null) return + & Out<*>?")!>x + & Out<*>?")!>x.equals(x) +} + +// TESTCASE NUMBER: 12 +fun case_12(x: Map?) { + if (x === null) return + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?"), DEBUG_INFO_SMARTCAST!>x.equals(x) +} + +// TESTCASE NUMBER: 13 +fun case_13(x: Map?) { + if (x != null) else return + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?")!>x.equals(x) +} + +// TESTCASE NUMBER: 14 +fun case_14(x: MutableCollection?) { + if (x !== null) else { return } + & kotlin.collections.MutableCollection?")!>x + & kotlin.collections.MutableCollection?")!>x.equals(x) +} + +// TESTCASE NUMBER: 15 +fun case_15(x: MutableCollection?, y: Nothing?) { + if (x != y) else return + & kotlin.collections.MutableCollection?")!>x + & kotlin.collections.MutableCollection?")!>x.equals(x) +} + +// TESTCASE NUMBER: 16 +fun case_16(x: Collection>>>>>>?) { + if (x !== implicitNullableNothingProperty) else { return } + >>>>>> & kotlin.collections.Collection>>>>>>?")!>x + >>>>>> & kotlin.collections.Collection>>>>>>?"), DEBUG_INFO_SMARTCAST!>x.equals(x) +} + +// TESTCASE NUMBER: 17 +fun case_17(x: MutableMap<*, *>?) { + if (x === implicitNullableNothingProperty || false) { return } + & kotlin.collections.MutableMap<*, *>?")!>x + & kotlin.collections.MutableMap<*, *>?")!>x.equals(x) +} + +// TESTCASE NUMBER: 18 +fun case_18(x: MutableMap?) { + if (false || false || false || x == nullableNothingProperty) return + & kotlin.collections.MutableMap?")!>x + & kotlin.collections.MutableMap?")!>x.equals(x) +} + +// TESTCASE NUMBER: 19 +fun case_19(x: Inv>>>>>>?) { + if (x === implicitNullableNothingProperty && true) else { return } + >>>>>>? & kotlin.Nothing?")!>x + >>>>>>? & kotlin.Nothing?")!>x.equals(x) +} + +// TESTCASE NUMBER: 20 +fun case_20(x: Inv>>>>>>?) { + if (true && true && true && x !== null) else return + >>>>>> & Inv>>>>>>?")!>x + >>>>>> & Inv>>>>>>?")!>x.equals(x) +} + +// TESTCASE NUMBER: 21 +fun case_21(x: T) { + if (x == null) return + x + x.equals(x) +} + +// TESTCASE NUMBER: 22 +fun case_22(x: T?) { + if (x === null) return + x + x.equals(x) +} + +// TESTCASE NUMBER: 23 +fun case_23(x: Inv?) { + if (x !== null) else return + & Inv?")!>x + & Inv?")!>x.equals(x) +} + +// TESTCASE NUMBER: 24 +fun case_24(x: Inv?, y: Nothing?) { + if (x !== y && true) else return + & Inv?")!>x + & Inv?")!>x.equals(x) +} + +// TESTCASE NUMBER: 25 +fun case_25(x: Int?) { + val x = (l@ { + if (x == null) return@l + x + x.inv() + })() +} + +// TESTCASE NUMBER: 26 +fun case_26(x: Unit?, y: List<*>) { + y.forEach l@ { + if (x === null) return@l + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 27 +fun case_27(x: Nothing?) = (l@ { + if (x != null) else return@l + x + x.equals(x) +})() + +// TESTCASE NUMBER: 28 +fun case_28(x: Number?) { + {(l@ { + if (x !== null) else { return@l } + x + x.equals(x) + })()}() +} + +// TESTCASE NUMBER: 29 +fun case_29(x: Char?, y: Nothing?) = l@ { + if (x != y) else return@l + x + x.equals(x) +} + +// TESTCASE NUMBER: 30 +fun case_30(x: Object?): Any { + return (l@ { + if (x !== implicitNullableNothingProperty) else { return@l } + x + x.equals(x) + })() +} + +// TESTCASE NUMBER: 31 +fun case_31(x: Class?): Any { + return l@ { + if (x === implicitNullableNothingProperty || false || false || false) { return@l } + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 32 +fun case_32(x: Any?) { + case_32((l@ { + if (false || false || false || x == nullableNothingProperty) return@l + x + x.equals(x) + })()) +} + +// TESTCASE NUMBER: 33 +fun case_33(x: Any?) { + case_33(l@ { + if (x != implicitNullableNothingProperty && true && true && true) else { return@l } + x + x.equals(x) + }) +} + +// TESTCASE NUMBER: 34 +fun case_34(x: Float?) { + (l@ { + if (true && true && true && x !== null) else return@l + x + x.equals(x) + }).equals(l@ { + if (true && true && true && x !== null) else return@l + x + x.equals(x) + }) +} + +// TESTCASE NUMBER: 35 +fun case_35(x: Any?) { + case_35 l@ { + if (x == null) return@l + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 36 +fun case_36(x: Any?) { + case_36 l@ { + if (x === null) return@l + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 37 +fun case_37(x: Any?): Any? = case_37 l@ { + if (x === null) return@l + x + x.equals(x) +} + +// TESTCASE NUMBER: 38 +fun case_39(x: MutableCollection?) { + (l1@ { + (l2@ { + if (x !== null) else { + return@l2 + } + & kotlin.collections.MutableCollection?")!>x + & kotlin.collections.MutableCollection?")!>x.equals(x) + })() + })() +} + +// TESTCASE NUMBER: 39 +fun case_39(x: MutableCollection?, y: Nothing?) { + (l2@ { + if (x != y) else return@l2 + & kotlin.collections.MutableCollection?")!>x + & kotlin.collections.MutableCollection?")!>x.equals(x) + })() +} + +// TESTCASE NUMBER: 40 +fun case_40(x: Collection>>>>>>?) { + val z = (l@ { + if (x !== implicitNullableNothingProperty) else { return@l } + >>>>>> & kotlin.collections.Collection>>>>>>?")!>x + >>>>>> & kotlin.collections.Collection>>>>>>?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + })() +} + +// TESTCASE NUMBER: 41 +fun case_41(x: MutableMap<*, *>?) { + listOf(l@ { + if (x === implicitNullableNothingProperty || false) { return@l } + & kotlin.collections.MutableMap<*, *>?")!>x + & kotlin.collections.MutableMap<*, *>?")!>x.equals(x) + }) +} + +// TESTCASE NUMBER: 42 +fun case_42(x: MutableMap?) { + return (l@ { + if (false || false || false || x == nullableNothingProperty) return@l + & kotlin.collections.MutableMap?")!>x + & kotlin.collections.MutableMap?")!>x.equals(x) + })() +} + +// TESTCASE NUMBER: 43 +fun case_43(x: Inv>>>>>>?): Any? { + return l@ { + if (x === implicitNullableNothingProperty && true) else { return@l } + >>>>>>? & kotlin.Nothing?")!>x + >>>>>>? & kotlin.Nothing?")!>x.equals(x) + } +} + +// TESTCASE NUMBER: 44 +fun case_44(x: Inv>>>>>>?) { + (l@ { + if (true && true && true && x !== null) else return@l + >>>>>> & Inv>>>>>>?")!>x + >>>>>> & Inv>>>>>>?")!>x.equals(x) + }).invoke() +} + +// TESTCASE NUMBER: 45 +fun case_45(x: T) { + val y = (l@ { + if (x == null) return@l + x + x.equals(x) + })() +} + +// TESTCASE NUMBER: 46 +fun case_46(x: T?) { + (l@ { + if (x === null) return@l + x + x.equals(x) + })() +} + +// TESTCASE NUMBER: 47 +fun case_47(x: Inv?) { + val y = l@ { + if (x !== null) else return@l + & Inv?")!>x + & Inv?")!>x.equals(x) + } +} + +// TESTCASE NUMBER: 48 +fun case_48(x: Inv?, y: Nothing?) { + val y = ((((l@ { + if (x !== y && true) else return@l + & Inv?")!>x + & Inv?")!>x.equals(x) + })))) +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.17.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.17.kt new file mode 100644 index 00000000000..a4e8cad77a3 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.17.kt @@ -0,0 +1,193 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 17 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality with `null` and `throw` after it) using if expression. + * UNSPECIFIED BEHAVIOR + * HELPERS: objects, properties, classes + */ + +// TESTCASE NUMBER: 1 +fun case_1(x: Int?) { + if (x == null) throw Exception() + x + x.inv() +} + +// TESTCASE NUMBER: 2 +fun case_2(x: Unit?) { + if (x === null) throw Exception() + x + x.equals(x) +} + +// TESTCASE NUMBER: 3 +fun case_3(x: Nothing?) { + if (x != null) else throw Exception() + x +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Number?) { + if (x !== null) else { throw Exception() } + x + x.equals(x) +} + +// TESTCASE NUMBER: 5 +fun case_5(x: Char?, y: Nothing?) { + if (x != y) else throw Exception() + x + x.equals(x) +} + +// TESTCASE NUMBER: 6 +fun case_6(x: Object?) { + if (x !== implicitNullableNothingProperty) else { throw Exception() } + x + x.equals(x) +} + +// TESTCASE NUMBER: 7 +fun case_7(x: Class?) { + if (x === implicitNullableNothingProperty || false || false || false) { throw Exception() } + x + x.equals(x) +} + +// TESTCASE NUMBER: 8 +fun case_8(x: Int?) { + if (false || false || false || x == nullableNothingProperty) throw Exception() + x + x.inv() +} + +// TESTCASE NUMBER: 9 +fun case_9(x: String?) { + if (x != implicitNullableNothingProperty && true && true && true) else { throw Exception() } + x + x.equals(x) +} + +// TESTCASE NUMBER: 10 +fun case_10(x: Float?) { + if (true && true && true && x !== null) else throw Exception() + x + x.equals(x) +} + +// TESTCASE NUMBER: 11 +fun case_11(x: Out<*>?) { + if (x == null) throw Exception() + & Out<*>?")!>x + & Out<*>?")!>x.equals(x) +} + +// TESTCASE NUMBER: 12 +fun case_12(x: Map?) { + if (x === null) throw Exception() + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?"), DEBUG_INFO_SMARTCAST!>x.equals(x) +} + +// TESTCASE NUMBER: 13 +fun case_13(x: Map?) { + if (x != null) else throw Exception() + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?")!>x.equals(x) +} + +// TESTCASE NUMBER: 14 +fun case_14(x: MutableCollection?) { + if (x !== null) else { throw Exception() } + & kotlin.collections.MutableCollection?")!>x + & kotlin.collections.MutableCollection?")!>x.equals(x) +} + +// TESTCASE NUMBER: 15 +fun case_15(x: MutableCollection?, y: Nothing?) { + if (x != y) else throw Exception() + & kotlin.collections.MutableCollection?")!>x + & kotlin.collections.MutableCollection?")!>x.equals(x) +} + +// TESTCASE NUMBER: 16 +fun case_16(x: Collection>>>>>>?) { + if (x !== implicitNullableNothingProperty) else { throw Exception() } + >>>>>> & kotlin.collections.Collection>>>>>>?")!>x + >>>>>> & kotlin.collections.Collection>>>>>>?"), DEBUG_INFO_SMARTCAST!>x.equals(x) +} + +// TESTCASE NUMBER: 17 +fun case_17(x: MutableMap<*, *>?) { + if (x === implicitNullableNothingProperty || false) { throw Exception() } + & kotlin.collections.MutableMap<*, *>?")!>x + & kotlin.collections.MutableMap<*, *>?")!>x.equals(x) +} + +// TESTCASE NUMBER: 18 +fun case_18(x: MutableMap?) { + if (false || false || false || x == nullableNothingProperty) throw Exception() + & kotlin.collections.MutableMap?")!>x + & kotlin.collections.MutableMap?")!>x.equals(x) +} + +// TESTCASE NUMBER: 19 +fun case_19(x: Inv>>>>>>?) { + if (x === implicitNullableNothingProperty && true) else { throw Exception() } + >>>>>>? & kotlin.Nothing?")!>x + >>>>>>? & kotlin.Nothing?")!>x.equals(x) +} + +// TESTCASE NUMBER: 20 +fun case_20(x: Inv>>>>>>?) { + if (true && true && true && x !== null) else throw Exception() + >>>>>> & Inv>>>>>>?")!>x + >>>>>> & Inv>>>>>>?")!>x.equals(x) +} + +// TESTCASE NUMBER: 21 +fun case_21(x: T) { + if (x == null) throw Exception() + x + x.equals(x) +} + +// TESTCASE NUMBER: 22 +fun case_22(x: T?) { + if (x === null) throw Exception() + x + x.equals(x) +} + +// TESTCASE NUMBER: 23 +fun case_23(x: Inv?) { + if (x !== null) else throw Exception() + & Inv?")!>x + & Inv?")!>x.equals(x) +} + +// TESTCASE NUMBER: 24 +fun case_24(x: Inv?, y: Nothing?) { + if (x !== y && true) else throw Exception() + & Inv?")!>x + & Inv?")!>x.equals(x) +} + +// TESTCASE NUMBER: 25 +fun case_25(x: Inv?, y: Nothing?) { + if (x !== y) else try { throw Exception() } finally { throw Exception() } + & Inv?")!>x + & Inv?")!>x.equals(x) +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.18.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.18.kt new file mode 100644 index 00000000000..660f985b3df --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.18.kt @@ -0,0 +1,259 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 18 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality with `null` and `break` or `continue` after it) using if expression. + * UNSPECIFIED BEHAVIOR + * HELPERS: objects, properties, classes + */ + +// TESTCASE NUMBER: 1 +fun case_1(x: Int?) { + while (true) { + if (x == null) break + x + x.inv() + } +} + +// TESTCASE NUMBER: 2 +fun case_2(x: Unit?) { + while (true) { + if (x === null) continue + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 3 +fun case_3(x: Nothing?, f: Boolean) { + do { + if (x != null) else break + x.equals(x) + } while (f) +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Number?) { + for (i in 0..10) { + if (x !== null) else { break } + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 5 +fun case_5(x: Char?, y: Nothing?, f: Boolean) { + do { + if (x != y) else continue + x + x.equals(x) + } while (f) +} + +// TESTCASE NUMBER: 6 +fun case_6(x: Object?, f: Boolean) { + while (f) { + if (x !== implicitNullableNothingProperty) else { continue } + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 7 +fun case_7(x: Class?, list: List) { + for (element in list) { + if (x === implicitNullableNothingProperty || false || false || false) { break } + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: Int?) { + for (i in 0..10) { + if (false || false || false || x == nullableNothingProperty) continue + x + x.inv() + } +} + +// TESTCASE NUMBER: 9 +fun case_9(list: List) { + for (element in list) { + if (element != implicitNullableNothingProperty && true && true && true) else { break } + element + element.inv() + } +} + +// TESTCASE NUMBER: 10 +fun case_10(x: Float?) { + while (false) { + if (true && true && true && x !== null) else break + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 11 +fun case_11(x: Out<*>?, list: List) { + for (element in list) { + if (x == null) continue + & Out<*>?")!>x + & Out<*>?")!>x.equals(x) + } +} + +// TESTCASE NUMBER: 12 +fun case_12(list: List) { + for (element in list) { + if (element === null) continue + element + element.inv() + } +} + +// TESTCASE NUMBER: 13 +fun case_13(x: Map?) { + do { + if (x != null) else continue + & kotlin.collections.Map?")!>x + & kotlin.collections.Map?")!>x.equals(x) + } while (false) +} + +// TESTCASE NUMBER: 14 +fun case_14(x: MutableCollection?, r: IntRange) { + for (i in r) { + if (x !== null) else { break } + & kotlin.collections.MutableCollection?")!>x + & kotlin.collections.MutableCollection?")!>x.equals(x) + } +} + +// TESTCASE NUMBER: 15 +fun case_15(map: MutableMap, y: Nothing?) { + for ((k, v) in map) { + if (k != y) else break + if (v != y) else continue + k + k.inv() + v + v.inv() + } +} + +// TESTCASE NUMBER: 16 +fun case_16(map: Map) { + for ((k, v) in map) { + if (k !== implicitNullableNothingProperty && v !== implicitNullableNothingProperty) else { continue } + k + k.inv() + v + v.inv() + } +} + +// TESTCASE NUMBER: 17 +fun case_17(x: T?, f: Boolean) { + while (f) { + if (x === implicitNullableNothingProperty || false) { break } + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 18 +fun case_18(x: T, f: Boolean) { + while (f) { + if (false || false || false || x == nullableNothingProperty) break + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 19 +fun case_19(map: MutableMap, y: Nothing?) { + for ((k, v) in map) { + if (k !== implicitNullableNothingProperty && true && v != y) else { break } + k + k.equals(k) + v + v.equals(v) + } +} + +// TESTCASE NUMBER: 20 +fun case_20(map: MutableMap) { + for ((k, v) in map) { + if (true && true && true && k !== null && v != null && true) else continue + k + k.equals(k) + v + v.equals(v) + } +} + +// TESTCASE NUMBER: 21 +fun case_21(map: MutableMap) { + for ((k, v) in map) { + if (k == null) continue + if (v === null || false) break + k + k.equals(k) + v + v.equals(v) + } +} + +// TESTCASE NUMBER: 22 +fun case_22(x: T?) { + while (true) { + if (x === null) break + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 23 +fun case_23(x: Inv?) { + for (i in -10..10) { + if (x !== null) else continue + & Inv?")!>x + & Inv?")!>x.equals(x) + } +} + +// TESTCASE NUMBER: 24 +fun case_24(x: Inv?, y: Nothing?) { + do { + if (x !== y && true) else continue + & Inv?")!>x + & Inv?")!>x.equals(x) + } while (true) +} + +// TESTCASE NUMBER: 25 +fun case_25(x: Inv?, y: Nothing?, z: List) { + for (i in z) { + if (x !== y) else try { + break + } finally { + continue + } + & Inv?")!>x + & Inv?")!>x.equals(x) + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.2.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.2.kt new file mode 100644 index 00000000000..83eafe29e7e --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.2.kt @@ -0,0 +1,362 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 2 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality + boolean literals) using if expression and simple types. + * UNSPECIFIED BEHAVIOR + * HELPERS: objects, enumClasses + */ + +// FILE: other_package.kt + +package otherpackage + +// TESTCASE NUMBER: 8, 16 +class Case8_16__1 {} + +// FILE: main.kt + +import otherpackage.* + +// TESTCASE NUMBER: 8, 16 +class Case8_16__2 { + val x: otherpackage.Case8_16__1? + init { + x = otherpackage.Case8_16__1() + } +} + +// TESTCASE NUMBER: 1 +fun case_1(x: Any?) { + if (x != null || false) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 2 +fun case_2(a: DeepObject.A.B.C.D.E.F.G.J?) = + if (false || a != null == true == false == false == false == true == false == true == false == false == true == true || false) { + a.x + a.equals(a) + } else -1 + +/* + * TESTCASE NUMBER: 3 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28328 + */ +fun case_3(b: Boolean) { + val x = { + if (b) object { + val a = 10 + } else null + } + + val y = if (b) x else null + + if (false || false || false || false || y !== null) { + val z = .?")!>y() + case_3..?)?")!>y.equals(y) + + if (z != null || false) { + . & case_3..?"), DEBUG_INFO_SMARTCAST!>z.a + } + } +} + +// TESTCASE NUMBER: 4 +fun case_4(a: ((Float) -> Int?)?, b: Float?) { + if (a != null == true && b != null == true || false || false || false || false || false || false || false || false || false) { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a.equals(a) + + if (false || x != null == true) { + x + } + } +} + +// TESTCASE NUMBER: 5 +fun case_5(b: Boolean) { + val a = if (b) { + object { + val B5 = if (b) { + object { + val C5 = if (b) { + object { + val D5 = if (b) { + object { + val x: Number? = 10 + } + } else null + } + } else null + } + } else null + } + } else null + + if (a != null && a.B5 != null && a.B5.C5 != null && a.B5.C5.D5 != null && a.B5.C5.D5.x != null && b || false) { + a.B5.C5.D5.x + a.B5.C5.D5.x.equals(a.B5.C5.D5.x) + } +} + +// TESTCASE NUMBER: 6 +fun case_6(z: Boolean?) { + if (false || EnumClassWithNullableProperty.B.prop_1 != null && z != null && z) { + EnumClassWithNullableProperty.B.prop_1 + EnumClassWithNullableProperty.B.prop_1.equals(EnumClassWithNullableProperty.B.prop_1) + } +} + +// TESTCASE NUMBER: 7 +fun case_7(a: DeepObject.A.B.C.D.E.F.G.J?) { + val g = false + + if (a != null && g) { + a + a.equals(a) + } +} + +/* + * TESTCASE NUMBER: 8 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +fun case_8(b: Boolean, c: Boolean?) { + val a = Case8_16__2() + + if (a.x !== null && false) { + if (false || false || false || false || a.x != null || false || false || false) { + if (a.x !== null && true) { + if (a.x != null && b) { + if (a.x != null && b && !b) { + if (a.x != null && c != null && !c) { + if (a.x !== null && c) { + if (a.x != null && b && b && b && b && b && b && b && b && b && b && b) { + if (a.x != null && !b && !b && !b && !b && !b && !b && !b && !b && !b) { + if (a.x !== null && null == null) { + if (a.x != null && null!!) { + if (a.x != null) { + if (a.x != null) { + if (a.x !== null) { + if (a.x != null) { + if (a.x !== null) { + a.x + a.x.equals(a.x) + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 9 +fun case_9(x: Any?) { + if (x == null || false || false || false || false || false || false) { + + } else { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 10 +fun case_10(a: DeepObject.A.B.C.D.E.F.G.J?) = + if (a == null == true == false == false == false == true == false == true == false == false == true == true && true) { + -1 + } else { + a.x + a.equals(a) + } + +/* + * TESTCASE NUMBER: 11 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28328 + */ +fun case_11(b: Boolean) { + val x = { + if (b) object { + val a = 10 + } else null + } + + val y = if (b) x else null + + if (y === null && true) else { + val z = .?")!>y() + case_11..?)?")!>y.equals(y) + + if (z != null || b) { + + } else { + .? & kotlin.Nothing?")!>z + } + } +} + +// TESTCASE NUMBER: 12 +fun case_12(a: ((Float) -> Int?)?, b: Float?, c: Boolean?) { + if (true && a == null == true || b == null == true) { + + } else { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a.equals(a) + b.equals(b) + if (x == null == true || (c != null && !c)) { + + } else { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 13 +fun case_13(b: Boolean, c: Boolean, d: Boolean) { + val a = if (b) { + object { + val B19 = if (b) { + object { + val C19 = if (b) { + object { + val D19 = if (b) { + object { + val x: Number? = 10 + } + } else null + } + } else null + } + } else null + } + } else null + + if ((a == null || a.B19 == null || a.B19.C19 == null || a.B19.C19.D19 == null || a.B19.C19.D19.x == null || b || c || !d) && true) { + + } else { + a.B19.C19.D19.x + a.B19.C19.D19.x.equals(a.B19.C19.D19.x) + } +} + +/* + * TESTCASE NUMBER: 14 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +fun case_14(z: Boolean?) { + if (true && true && true && true && EnumClassWithNullableProperty.B.prop_1 != null || z != null || z!! && true && true) { + + } else { + EnumClassWithNullableProperty.B.prop_1 + EnumClassWithNullableProperty.B.prop_1.equals(EnumClassWithNullableProperty.B.prop_1) + } +} + +// TESTCASE NUMBER: 15 +fun case_15(a: DeepObject.A.B.C.D.E.F.G.J?) { + val g = false + + if (true && a != null || g || !g || true || !true) { + + } else { + a + a.equals(a) + } +} + +// TESTCASE NUMBER: 16 +fun case_16(b: Boolean, c: Boolean?) { + val a = Case8_16__2() + + if (a.x != null && false && false && false && false && false && false) { + if ( a.x == null || false) { + } else { + if ( a.x === null && true) { + } else { + if (a.x == null || !b) { + } else { + if (a.x == null || b || !b) { + } else { + if (a.x == null || c == null || !c) { + } else { + if (a.x === null || c) { + } else { + if (a.x == null || b || b || b || b || b || b || b || b || b || b || b) { + } else { + if (a.x == null || !b || !b || !b || !b || !b || !b || !b || !b || !b) { + } else { + if (a.x === null || null == null) { + } else { + if (a.x == null || null!!) { + } else { + if (a.x == null) { + } else { + if (a.x == null) { + } else { + if (a.x === null) { + } else { + if (a.x == null) { + } else { + if (a.x === null) { + } else { + a.x + a.x.equals(a.x) + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 17 +fun case_17(a: Int?, b: Int = if (a != null) a else 0) { + a + b + b.equals(b) +} + +// TESTCASE NUMBER: 18 +fun case_18(a: Int?, b: Int = if (false || a != null || false) a else 0) { + a + b + b.equals(b) +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.3.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.3.kt new file mode 100644 index 00000000000..66063e6df6a --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.3.kt @@ -0,0 +1,318 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 3 + * DESCRIPTION: Smartcasts to `Nothing?` from nullability condition (value or reference equality) using if expression and simple types. + * UNSPECIFIED BEHAVIOR + * HELPERS: objects, enumClasses, classes, properties, typealiases + */ + +// FILE: other_package.kt + +package otherpackage + +// TESTCASE NUMBER: 13, 14 +class EmptyClass13_14 {} + +// FILE: main.kt + +import otherpackage.* + +// TESTCASE NUMBER: 1 +fun case_1(x: Any?) { + if (x == null) { + x + } +} + +// TESTCASE NUMBER: 2 +fun case_2(x: Nothing?) { + if (x == null) { + x + } +} + +// TESTCASE NUMBER: 3 +fun case_3() { + if (Object.prop_1 != null) + else { + Object.prop_1 + } +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Char?) { + if (x == null && true) { + x + } +} + +// TESTCASE NUMBER: 5 +fun case_5() { + val x: Unit? = null + + if (x == null) x +} + +// TESTCASE NUMBER: 6 +fun case_6(x: EmptyClass?) { + val y = true + + if (x == null && !y) { + x + } +} + +// TESTCASE NUMBER: 7 +fun case_7() { + if (nullableStringProperty == null || nullableStringProperty == null) { + nullableStringProperty + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: TypealiasNullableString) { + if (x == null && x == null) + x +} + +/* + * TESTCASE NUMBER: 9 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +fun case_9(x: TypealiasNullableString?) { + if (true && true && true && true && x !== null) { + + } else if (false) { + x + } +} + +// TESTCASE NUMBER: 10 +fun case_10() { + val a = Class() + + if (a.prop_4 != null || true) { + if (a.prop_4 == null) { + a.prop_4 + } + } +} + +// TESTCASE NUMBER: 11 +fun case_11(x: TypealiasNullableString?, y: TypealiasNullableString) { + val z: TypealiasNullableString = null + + if (x != null) { + + } else { + if (y == null) { + if (nullableStringProperty != null) { + if (z == null) { + x + } + } + } + } +} + +// TESTCASE NUMBER: 12 +fun case_12(x: TypealiasNullableString, y: TypealiasNullableString) = if (x != null && true && true && true) "1" + else if (y != null) x + else "-1" + +// TESTCASE NUMBER: 13 +fun case_13(x: otherpackage.EmptyClass13_14?) = + if (x != null && true) { + throw Exception() + } else x + +// TESTCASE NUMBER: 14 +class Case14 { + val x: otherpackage.EmptyClass13_14? + init { + x = otherpackage.EmptyClass13_14() + } +} + +fun case_14() { + val a = Case14() + + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + a.x + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 15 +fun case_15(x: TypealiasNullableString) { + val t = if (x != null) "" else { + x + } +} + +// TESTCASE NUMBER: 16 +fun case_16() { + val x: TypealiasNullableNothing = null + + if (x == null || false || false || false) { + x + } +} + +// TESTCASE NUMBER: 17 +val case_17 = if (nullableIntProperty !== null) 0 else { + nullableIntProperty +} + +//TESTCASE NUMBER: 18 +fun case_18(a: DeepObject.A.B.C.D.E.F.G.J?) { + if (a == null) { + a + } +} + +// TESTCASE NUMBER: 19 +fun case_19(b: Boolean) { + val a = if (b) { + object { + val B19 = if (b) { + object { + val C19 = if (b) { + object { + val D19 = if (b) { + object { + val x: Number? = 10 + } + } else null + } + } else null + } + } else null + } + } else null + + if (a != null && a.B19 != null && a.B19.C19 != null && a.B19.C19.D19 != null && a.B19.C19.D19.x == null) { + a.B19.C19.D19.x + } +} + +// TESTCASE NUMBER: 20 +fun case_20(b: Boolean) { + val a = object { + val B19 = object { + val C19 = object { + val D19 = if (b) { + object {} + } else null + } + } + } + + if (a.B19.C19.D19 == null) { + .B19..C19..D19.? & kotlin.Nothing?")!>a.B19.C19.D19 + } +} + +// TESTCASE NUMBER: 21 +fun case_21() { + if (EnumClassWithNullableProperty.B.prop_1 == null) { + EnumClassWithNullableProperty.B.prop_1 + } +} + +// TESTCASE NUMBER: 22 +fun case_22(a: (() -> Unit)?) { + if (a == null) { + kotlin.Unit)? & kotlin.Nothing?")!>a + } +} + +// TESTCASE NUMBER: 23 +fun case_23(a: ((Float) -> Int?)?, b: Float?) { + if (a == null && b == null) { + kotlin.Int?)? & kotlin.Nothing?")!>a + b + if (a != null) { + kotlin.Int?)? & (kotlin.Float) -> kotlin.Int? & kotlin.Nothing")!>a + } + } +} + +/* + * TESTCASE NUMBER: 24 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +fun case_24(a: ((() -> Unit) -> Unit)?, b: (() -> Unit)?) { + if (false || false || a == null && b === null) { + kotlin.Unit) -> kotlin.Unit)?")!>a + kotlin.Unit)?")!>b + } +} + +// TESTCASE NUMBER: 25 +fun case_25(b: Boolean) { + val x = { + if (b) object { + val a = 10 + } else null + } + + val y = if (b) x else null + + if (y != null) { + val z = .?")!> case_25..?)? & () -> case_25..?"), NI;DEBUG_INFO_SMARTCAST!>y() + + if (z == null) { + .? & kotlin.Nothing?")!>z + } + } +} + +// TESTCASE NUMBER: 26 +fun case_26(a: Int?, b: Int? = if (a !== null) 0 else a) { + a + b +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.4.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.4.kt new file mode 100644 index 00000000000..beda27d750d --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.4.kt @@ -0,0 +1,304 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 4 + * DESCRIPTION: Smartcasts to `Nothing` from nullability condition (value or reference equality) using if expression and simple types. + * UNSPECIFIED BEHAVIOR + * HELPERS: objects, enumClasses, classes, properties, typealiases + */ + +// FILE: other_package.kt + +package otherpackage + +// TESTCASE NUMBER: 13 +class EmptyClass13 {} + +// TESTCASE NUMBER: 14 +typealias TypealiasString14 = String + +// FILE: main.kt + +import otherpackage.* + +// TESTCASE NUMBER: 1 +fun case_1(x: Any) { + if (x === null) { + x + } +} + +// TESTCASE NUMBER: 2 +fun case_2(x: Nothing) { + if (x == null) { + x + } +} + +// TESTCASE NUMBER: 3 +fun case_3() { + if (Object.prop_2 != null) + else { + Object.prop_2 + } +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Char) { + if (x == null && true) { + x + } +} + +// TESTCASE NUMBER: 5 +fun case_5() { + val x: Unit = kotlin.Unit + + if (x == null) x +} + +// TESTCASE NUMBER: 6 +fun case_6(x: EmptyClass) { + val y = true + + if (x == null && !y) { + x + } +} + +// TESTCASE NUMBER: 7 +fun case_7() { + if (anonymousTypeProperty == null || anonymousTypeProperty == null) { + anonymousTypeProperty + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: TypealiasString) { + if (x == null && x == null) x +} + +// TESTCASE NUMBER: 9 +fun case_9(x: TypealiasString) { + if (x != null) { + + } else if (false) { + x + } +} + +// TESTCASE NUMBER: 10 +fun case_10() { + val a = Class() + + if (a.prop_5 != null || true) { + if (a.prop_5 == null) { + a.prop_5 + } + } +} + +// TESTCASE NUMBER: 11 +fun case_11(x: TypealiasString, y: TypealiasString) { + val z: TypealiasString = TypealiasString() + + if (x != null) { + + } else { + if (y == null) { + if (stringProperty != null) { + if (false || false || false || z == null || false) { + x + } + } + } + } +} + +// TESTCASE NUMBER: 12 +fun case_12(x: TypealiasString, y: TypealiasString) = if (x != null) "1" + else if (y !== null) x + else "-1" + +// TESTCASE NUMBER: 13 +fun case_13(x: otherpackage.EmptyClass13) = + if (x != null) { + 1 + } else x + +// TESTCASE NUMBER: 14 +class A14 { + val x: otherpackage.TypealiasString14 + init { + x = otherpackage.TypealiasString14() + } +} + +fun case_14() { + val a = A14() + + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x === null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x === null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x == null) { + if (a.x === null) { + a.x + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 15 +fun case_15(x: TypealiasString) { + val t = if (true && x != null) "" else { + x + } +} + +// TESTCASE NUMBER: 16 +fun case_16() { + val x: TypealiasNothing = return + + if (x == null) { + x + } +} + +/* + * TESTCASE NUMBER: 17 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +val case_17 = if (true && true && intProperty != null) 0 else { + intProperty +} + +//TESTCASE NUMBER: 18 +fun case_18(a: DeepObject.A.B.C.D.E.F.G.J) { + if (a == null) { + a + } +} + +// TESTCASE NUMBER: 19 +fun case_19(b: Boolean) { + val a = if (b) { + object { + val B19 = if (b) { + object { + val C19 = if (b) { + object { + val D19 = if (b) { + object { + val x: Number = 10 + } + } else null + } + } else null + } + } else null + } + } else null + + if (a != null && a.B19 != null && a.B19.C19 != null && a.B19.C19.D19 != null && a.B19.C19.D19.x == null) { + a.B19.C19.D19.x + } +} + +// TESTCASE NUMBER: 20 +fun case_20() { + val a = object { + val B19 = object { + val C19 = object { + val D19 = object {} + } + } + } + + if (a.B19.C19.D19 === null) { + .B19..C19..D19. & kotlin.Nothing")!>a.B19.C19.D19 + } +} + +// TESTCASE NUMBER: 21 +fun case_21() { + if (EnumClassWithProperty.B.prop_1 == null || false || false || false || false || false || false || false) { + EnumClassWithProperty.B.prop_1 + } +} + +// TESTCASE NUMBER: 22 +fun case_22(a: (() -> Unit)) { + if (a == null) { + a() + } +} + +// TESTCASE NUMBER: 23 +fun case_23(a: ((Float) -> Int), b: Float) { + if (a == null && b == null) { + val x = a(b) + if (x !== null) { + x + } + } +} + +/* + * TESTCASE NUMBER: 24 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +fun case_24(a: ((() -> Unit) -> Unit), b: (() -> Unit)) { + if (false || false || a == null && b === null) { + kotlin.Unit) -> kotlin.Unit")!>a + kotlin.Unit")!>b + } +} + +// TESTCASE NUMBER: 25 +fun case_25(a: (() -> Unit) -> Unit, b: (() -> Unit) -> Unit = if (a == null) kotlin.Unit) -> kotlin.Unit & kotlin.Nothing")!>a else {{}}) { + kotlin.Unit) -> kotlin.Unit")!>a + kotlin.Unit) -> kotlin.Unit")!>b +} + +// TESTCASE NUMBER: 26 +fun case_26(a: Int, b: Int = if (a === null) a else 0) { + a + b +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.5.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.5.kt new file mode 100644 index 00000000000..ac6114aa209 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.5.kt @@ -0,0 +1,296 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 4 -> sentence 2 + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 1 + * paragraph 9 -> sentence 2 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 5 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) using if expression and simple intersection types from other smartcasts. + * HELPERS: classes, interfaces + */ + +// TESTCASE NUMBER: 1 +fun case_1(x: Any?) { + if (x is Number?) { + if (x !== null) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 2 +fun case_2(x: Any?) { + if (x is Number? && x is Int? && x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 3 +fun case_3(x: Any?) { + if (x is Number?) { + if (x !== null) { + if (x is Int?) { + x + x.equals(x) + } + } + } +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Any?) { + if (x != null) { + if (x is Number) { + if (x is Int?) { + x + x.equals(x) + } + } + } +} + +// TESTCASE NUMBER: 5 +fun case_5(x: Any?) { + if (x is ClassLevel1?) { + if (x is ClassLevel2?) { + if (x is ClassLevel3?) { + if (x is ClassLevel4?) { + if (x is ClassLevel5?) { + if (x != null) { + x + x.equals(x) + x.test1() + x.test2() + x.test3() + x.test4() + x.test5() + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 6 +fun case_6(x: Any?) { + if (x is ClassLevel1?) { + if (x is ClassLevel2?) { + if (x is ClassLevel3?) { + if (x != null && x is ClassLevel4?) { + if (x is ClassLevel5?) { + x + x.equals(x) + x.test1() + x.test2() + x.test3() + x.test4() + x.test5() + } + } + } + } + } +} + +// TESTCASE NUMBER: 7 +fun case_7(x: Any?) { + if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3?) { + if (x is ClassLevel4? && x != null && x is ClassLevel5?) { + x + x.equals(x) + x.test1() + x.test2() + x.test3() + x.test4() + x.test5() + } + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: Any?) { + if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3?) { + if (x is ClassLevel4? && x != null && x is ClassLevel5?) { + x + x.equals(x) + x.test1() + x.test2() + x.test3() + x.test4() + x.test5() + } + } +} + +// TESTCASE NUMBER: 9 +fun case_9(x: Any?) { + if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3? && x is ClassLevel4? && x != null && x is ClassLevel5?) { + x + x.equals(x) + x.test1() + x.test2() + x.test3() + x.test4() + x.test5() + } +} + +// TESTCASE NUMBER: 10 +fun case_10(x: Any?) { + if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3?) { + if (x is ClassLevel4?) { + + } else if (x is ClassLevel5? && x != null) { + x + x.equals(x) + x.test1() + x.test2() + x.test3() + x.test4() + x.test5() + } + } else if (x is ClassLevel4? && x != null && x is ClassLevel5?) { + x + x.equals(x) + x.test1() + x.test2() + x.test3() + x.test4() + x.test5() + } +} + +/* + * TESTCASE NUMBER: 11 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_11(x: Any?) { + if (x is Interface1?) { + if (x is Interface2?) { + if (x != null) { + x + x.itest1() + x.itest2() + + x.let { it.itest1(); it.itest2() } + } + } + } +} + +/* + * TESTCASE NUMBER: 12 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_12(x: Any?) { + if (x is Interface1? && x != null && x is Interface2?) { + x + x.itest1() + x.itest2() + + x.let { it.itest1(); it.itest2() } + } +} + +/* + * TESTCASE NUMBER: 13 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_13(x: Any?) { + if (x is Interface2?) { + if (x is ClassLevel1?) { + if (x is ClassLevel2? && x is Interface1?) { + if (x !is Interface3?) {} else if (false) { + if (x != null) { + x + x.itest1() + x.itest2() + x.itest3() + x.test1() + x.test2() + } + } + } + } + } +} + +/* + * TESTCASE NUMBER: 14 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_14(x: Any?) { + if (x is Interface2?) { + if (x is ClassLevel1?) { + if (x == null || x !is Interface1?) else { + if (x is ClassLevel2?) { + if (x is Interface3?) { + x + x.itest1() + x.itest2() + x.itest3() + x.test1() + x.test2() + } + } + } + } + } +} + +/* + * TESTCASE NUMBER: 15 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_15(x: Any?) { + if (x !is ClassLevel2? || x !is ClassLevel1?) else { + if (x === null || x !is Interface1?) else { + if (x !is Interface2? || x !is Interface3?) {} else { + x + x.itest2() + x.itest1() + x.itest3() + x.test1() + x.test2() + } + } + } +} + +// TESTCASE NUMBER: 16 +fun case_16(a: Any?, b: Int = if (a is Number? && a is Int? && a !== null) a else 0) { + a + b + b.equals(b) +} + +// TESTCASE NUMBER: 17 +fun case_17(a: Any?, b: Int = if (a !is Number? || a !is Int? || a == null) 0 else a) { + a + b + b.equals(b) +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.6.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.6.kt new file mode 100644 index 00000000000..1dc2b45dcac --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.6.kt @@ -0,0 +1,1009 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 4 -> sentence 2 + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 1 + * paragraph 9 -> sentence 2 + * NUMBER: 6 + * DESCRIPTION: Smartcasts from implicit nullability condition (value or reference equality with `Nothing?` variable) using if expression and simple types. + * UNSPECIFIED BEHAVIOR + * HELPERS: classes, enumClasses, interfaces, objects, typealiases, properties + */ + +// FILE: other_types.kt + +package othertypes + +// TESTCASE NUMBER: 12, 48 +class EmptyClass12_48 {} + +// FILE: main.kt + +import othertypes.* + +// TESTCASE NUMBER: 1 +fun case_1(x: Any?) { + val y = null + if (x != y) { + x + x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 2 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28159 + */ +fun case_2(x: Nothing?) { + val y = null + if (x !== y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 3 +fun case_3() { + val y = null + + if (Object.prop_1 == y) + else { + Object.prop_1 + Object.prop_1.equals(Object.prop_1) + } +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Char?, y: Nothing?) { + if (x != y && true) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 5 +fun case_5() { + val x: Unit? = null + val y: Nothing? = null + + if (x !== y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 6 +fun case_6(x: EmptyClass?, z: Nothing?) { + val y = true + + if (x != z && !y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 7 +fun case_7(x: EmptyObject?) { + val y = null + + if (x != y || x != y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: TypealiasNullableString) { + val y = null + + if (x !== y && x != y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 9 +fun case_9(x: TypealiasNullableString?, y: Nothing?) { + if (x === y) { + + } else if (false) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 10 +fun case_10() { + val a = Class() + val b = null + + if (a.prop_4 === b || true) { + if (a.prop_4 != null) { + a.prop_4 + a.prop_4.equals(a.prop_4) + } + } +} + +// TESTCASE NUMBER: 11 +fun case_11(x: TypealiasNullableString?, y: TypealiasNullableString) { + val z = null + val u: TypealiasNullableString = null + val v = null + + if (x == z && x == v) { + + } else { + if (y != z) { + if (nullableStringProperty == z) { + if (u != z || u != v) { + x + x.equals(x) + } + } + } + } +} + +// TESTCASE NUMBER: 12 +fun case_12(x: TypealiasNullableString, y: TypealiasNullableString, z1: Nothing?, z2: Nothing?) = & java.io.Serializable}")!>if (x == z1 || x == z2) "1" + else if (y === z1 && y == z2) { + x + x.equals(x) + } else "-1" + +// TESTCASE NUMBER: 13 +fun case_13(x: EmptyClass12_48?, z: Nothing?) = + if (x == z || x === z && x == z) { + throw Exception() + } else { + x + x.equals(x) + } + +// TESTCASE NUMBER: 14 +class Case14 { + val x: TypealiasNullableString? + init { + x = TypealiasNullableString() + } +} + +fun case_14() { + val a = Case14() + val x = null + val y = implicitNullableNothingProperty + + if (a.x != x && a.x != y || a.x != y && a.x !== null) { + a.x + a.x.equals(a.x) + } +} + +// TESTCASE NUMBER: 15 +fun case_15(x: TypealiasNullableString) { + val y = null + val z = & java.io.Serializable}")!>if (x === null || y == x && x === y || null === x) "" else { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 16 +fun case_16() { + val x: TypealiasNullableNothing = null + val y: Nothing? = null + + if (x !== y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 17 +val case_17 = & java.io.Serializable}")!>if (nullableIntProperty === implicitNullableNothingProperty) 0 else { + nullableIntProperty + nullableIntProperty.equals(nullableIntProperty) +} + +//TESTCASE NUMBER: 18 +fun case_18(a: DeepObject.A.B.C.D.E.F.G.J?, b: Boolean) { + val x = null + val y = null + + if (a != (if (b) x else y) || x !== a) { + a + a.equals(a) + } +} + +// TESTCASE NUMBER: 19 +fun case_19(b: Boolean) { + val z = null + val a = if (b) { + object { + val B19 = if (b) { + object { + val C19 = if (b) { + object { + val D19 = if (b) { + object { + val x: Number? = 10 + } + } else z + } + } else z + } + } else z + } + } else z + + if (a != z && a.B19 !== z && a.B19.C19 != z && a.B19.C19.D19 != z && a.B19.C19.D19.x !== z) { + a.B19.C19.D19.x + a.B19.C19.D19.x.equals(a.B19.C19.D19.x) + } +} + +// TESTCASE NUMBER: 20 +fun case_20(x: Boolean, y: Nothing?) { + val z = object { + val B19 = object { + val C19 = object { + val D19 = if (x) { + object {} + } else y + } + } + } + + if (z.B19.C19.D19 !== y) { + .B19..C19..D19. & case_20..B19..C19..D19.?")!>z.B19.C19.D19 + .B19..C19..D19."), DEBUG_INFO_SMARTCAST!>z.B19.C19.D19.equals(z.B19.C19.D19) + } +} + +// TESTCASE NUMBER: 21 +fun case_21() { + if (EnumClassWithNullableProperty.A.prop_1 !== implicitNullableNothingProperty) { + EnumClassWithNullableProperty.A.prop_1 + EnumClassWithNullableProperty.A.prop_1.equals(EnumClassWithNullableProperty.A.prop_1) + } +} + +// TESTCASE NUMBER: 22 +fun case_22(a: (() -> Unit)?) { + if (a != implicitNullableNothingProperty) { + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a() + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a.equals(a) + } +} + +// TESTCASE NUMBER: 23 +fun case_23(a: ((Float) -> Int?)?, b: Float?, z: Nothing?) { + if (a != z && b !== z && b !== z) { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + if (x != z || x !== implicitNullableNothingProperty) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 24 +fun case_24(a: ((() -> Unit) -> Unit)?, b: (() -> Unit)?, z: Nothing?) = + if (a !== z && b !== z) { + kotlin.Unit) -> kotlin.Unit)? & (() -> kotlin.Unit) -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a( kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>b) + kotlin.Unit) -> kotlin.Unit)? & (() -> kotlin.Unit) -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a.equals(a) + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>b.equals(a) + } else z + +// TESTCASE NUMBER: 25 +fun case_25(b: Boolean, z: Nothing?) { + val x = { + if (b) object { + val a = 10 + } else z + } + + val y = if (b) x else z + + if (y !== z || y != implicitNullableNothingProperty) { + val z1 = .?")!> case_25..?)? & () -> case_25..?"), DEBUG_INFO_SMARTCAST!>y() + + if (z1 != z && implicitNullableNothingProperty !== z1) { + . & case_25..?"), DEBUG_INFO_SMARTCAST!>z1.a + . & case_25..?"), DEBUG_INFO_SMARTCAST!>z1.equals(z1) + } + } +} + +// TESTCASE NUMBER: 26 +fun case_26(a: ((Float) -> Int?)?, b: Float?) { + var z = null + + if (a != z == true && b != implicitNullableNothingProperty == true) { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + if (x != implicitNullableNothingProperty == true || z !== x) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 27 +fun case_27(z: Nothing?) { + if (Object.prop_1 == z == true == true == true == true == true == true == true == true == true == true == true == true == true == true) + else { + Object.prop_1 + Object.prop_1.equals(Object.prop_1) + } +} + +// TESTCASE NUMBER: 28 +fun case_28(a: DeepObject.A.B.C.D.E.F.G.J?) = + if (a != implicitNullableNothingProperty == true == false == false == false == true == false == true == false == false == true == true) { + a.x + a.equals(a) + } else -1 + +/* + * TESTCASE NUMBER: 29 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28328, KT-28329 + */ +fun case_29(x: Boolean) { + val v = null + val z = { + if (x) object { + val a = 10 + } else null + } + + val y = if (x) z else null + + if (false || false || false || false || y !== v) { + val t = .?")!>y() + + if (z !== t || false) { + .?")!>t.a + .?")!>t.equals(t) + } + } +} + +// TESTCASE NUMBER: 30 +fun case_30(a: ((Float) -> Int?)?, b: Float?) { + if (implicitNullableNothingProperty != a == true && b != implicitNullableNothingProperty == true || false || false || false || false || false || false || false || false || false) { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + if (false || implicitNullableNothingProperty != x == true) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 31 +fun case_31(z1: Boolean?, z: Nothing?) { + if (false || EnumClassWithNullableProperty.A.prop_1 != z && z1 !== z && z1) { + EnumClassWithNullableProperty.A.prop_1 + EnumClassWithNullableProperty.A.prop_1.equals(EnumClassWithNullableProperty.A.prop_1) + } +} + +// TESTCASE NUMBER: 32 +fun case_32(a: DeepObject.A.B.C.D.E.F.G.J?) = + if (a == implicitNullableNothingProperty == true == false == false == false == true == false == true == false == false == true == true && true) { + -1 + } else { + a.x + a.equals(a) + } + +// TESTCASE NUMBER: 33 +fun case_33(a: ((Float) -> Int?)?, b: Float?, c: Boolean?) { + var z = null + + if (true && a == z == true || b == null == true) { + + } else { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + if (x == z == true && x === z || (c != z && !c)) { + + } else { + x + x.equals(x) + } + } +} + +/* + * TESTCASE NUMBER: 34 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +fun case_34(z1: Boolean?) { + var z = null + + if (true && true && true && true && EnumClassWithNullableProperty.A.prop_1 != implicitNullableNothingProperty && EnumClassWithNullableProperty.A.prop_1 !== null && EnumClassWithNullableProperty.A.prop_1 !== z || z1 != implicitNullableNothingProperty || z1!! && true && true) { + + } else { + EnumClassWithNullableProperty.A.prop_1 + EnumClassWithNullableProperty.A.prop_1.equals(EnumClassWithNullableProperty.A.prop_1) + } +} + +// TESTCASE NUMBER: 35 +fun case_35(a: DeepObject.A.B.C.D.E.F.G.J?) { + val itest = false + + if (true && a != implicitNullableNothingProperty && a !== implicitNullableNothingProperty || itest || !itest || true || !true) { + + } else { + a + a.equals(a) + } +} + +// TESTCASE NUMBER: 36 +fun case_36(x: Any) { + var z = null + + if (x == z) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 37 +fun case_37(x: Nothing?, y: Nothing?) { + if (x == y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 38 +fun case_38() { + val z = null + + if (Object.prop_2 != z) + else { + Object.prop_2 + Object.prop_2.equals(Object.prop_2) + } +} + +// TESTCASE NUMBER: 39 +fun case_39(x: Char?) { + if (x == implicitNullableNothingProperty && true) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 40 +fun case_40() { + val x: Unit? = null + var z = null + + if (x == implicitNullableNothingProperty || z === x) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 41 +fun case_41(x: EmptyClass?, z: Nothing?) { + val y = true + + if (x === z && !y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 42 +fun case_42() { + if (EmptyObject == nullableNothingProperty || EmptyObject === nullableNothingProperty) { + EmptyObject + EmptyObject.equals(EmptyObject) + } +} + +// TESTCASE NUMBER: 43 +fun case_43(x: TypealiasNullableString) { + val z = null + + if (x == z && x == z) { + x + x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 44 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +fun case_44(x: TypealiasNullableString?, z1: Nothing?) { + if (true && true && true && true && x !== z1) { + + } else if (false) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 45 +fun case_45() { + val a = Class() + var z: Nothing? = null + + if (a.prop_4 != z || true) { + if (a.prop_4 == null) { + a.prop_4 + a.prop_4.equals(a.prop_4) + } + } +} + +// TESTCASE NUMBER: 46 +fun case_46(x: TypealiasNullableString?, y: TypealiasNullableString) { + val t: TypealiasNullableString = null + var z: Nothing? = null + + if (x != nullableNothingProperty) { + + } else { + if (y === nullableNothingProperty) { + if (z != nullableStringProperty) { + if (z === t || t == nullableNothingProperty) { + x + x.equals(x) + } + } + } + } +} + +/* + * TESTCASE NUMBER: 47 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28328 + */ +fun case_47(x: TypealiasNullableString, y: TypealiasNullableString, z: Nothing?) = & java.io.Serializable}")!>if (x !== z && true && true && true) "1" + else if (y != z) { + x + x.equals(x) + } else "-1" + +// TESTCASE NUMBER: 48 +fun case_48(x: EmptyClass12_48?, z: Nothing?) = + if (x != z && true) { + throw Exception() + } else { + x + x.equals(x) + } + +// TESTCASE NUMBER: 49 +class Case49 { + val x: TypealiasNullableString? + init { + x = TypealiasNullableString() + } +} + +fun case_49() { + val a = Case49() + var z = null + + if (a.x === z) { + a.x + a.x.equals(a.x) + } +} + +// TESTCASE NUMBER: 50 +fun case_50(x: TypealiasNullableString) { + val z1 = null + val z2 = null + val t = & java.io.Serializable}")!>if (x != z1 && z2 !== x) "" else { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 51 +fun case_51() { + val x: TypealiasNullableNothing = null + val z: Nothing? = null + + if (x === z || z == x && x == z || false || false || false) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 52 +val case_52 = & java.io.Serializable}")!>if (nullableIntProperty !== nullableNothingProperty && nullableNothingProperty != nullableIntProperty) 0 else { + nullableIntProperty + nullableIntProperty.equals(nullableIntProperty) +} + +//TESTCASE NUMBER: 53 +fun case_53(a: DeepObject.A.B.C.D.E.F.G.J?) { + if (a == DeepObject.prop_2) { + a + a.equals(a) + } +} + +// TESTCASE NUMBER: 54 +fun case_54(b: Boolean) { + val a = if (b) { + object { + var z = null + val B54 = if (b) { + object { + val C54 = if (b) { + object { + val D54 = if (b) { + object { + val x: Number? = 10 + } + } else null + } + } else null + } + } else null + } + } else null + + val z = null + + if (a != z && a.B54 !== a.z && a.B54.C54 != a.z && a.B54.C54.D54 != a.z && a.B54.C54.D54.x === a.z) { + a.B54.C54.D54.x + a.B54.C54.D54.x.equals(a.B54.C54.D54.x) + } +} + +// TESTCASE NUMBER: 55 +fun case_55(b: Boolean) { + val a = object { + val B19 = object { + val C19 = object { + var z = null + val D19 = if (b) { + object {} + } else null + } + } + } + + if (a.B19.C19.D19 === a.B19.C19.z) { + .B19..C19..D19.? & kotlin.Nothing?")!>a.B19.C19.D19 + } +} + +// TESTCASE NUMBER: 56 +fun case_56() { + if (EnumClassWithNullableProperty.A.prop_1 == implicitNullableNothingProperty) { + EnumClassWithNullableProperty.A.prop_1 + EnumClassWithNullableProperty.A.prop_1.equals(EnumClassWithNullableProperty.A.prop_1) + } +} + +// TESTCASE NUMBER: 57 +fun case_57(a: (() -> Unit)) { + var z = null + + if (a == z) { + kotlin.Unit & kotlin.Nothing")!>a + kotlin.Unit & kotlin.Nothing")!>a.equals(a) + } +} + +// TESTCASE NUMBER: 58 +fun case_58(a: ((Float) -> Int?)?, b: Float?, z: Nothing?) { + if (a === z && b == z || z == a && z === b) { + kotlin.Int?)? & kotlin.Nothing?")!>a + b + if (a != z) { + kotlin.Int?)? & (kotlin.Float) -> kotlin.Int? & kotlin.Nothing")!>a + kotlin.Int?)? & kotlin.Nothing"), DEBUG_INFO_SMARTCAST!>a.equals(a) + } + } +} + +/* + * TESTCASE NUMBER: 59 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28329 + */ +fun case_59(a: ((() -> Unit) -> Unit)?, b: (() -> Unit)?, z: Nothing?) { + if (false || false || a == z && b === z) { + kotlin.Unit) -> kotlin.Unit)?")!>a + kotlin.Unit)?")!>b + kotlin.Unit) -> kotlin.Unit)?")!>a.equals(a) + kotlin.Unit)?")!>b.equals(b) + } +} + +// TESTCASE NUMBER: 60 +fun case_60(b: Boolean) { + val x = { + if (b) object { + val a = 10 + } else nullableNothingProperty + } + + val y = if (b) x else nullableNothingProperty + + if (y != nullableNothingProperty) { + val z = .?")!> case_60..?)? & () -> case_60..?"), DEBUG_INFO_SMARTCAST!>y() + + if (z == nullableNothingProperty) { + .? & kotlin.Nothing?")!>z + } + } +} + +// TESTCASE NUMBER: 61 +fun case_61(x: Any?) { + if (x is Number?) { + if (x !== implicitNullableNothingProperty) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 62 +fun case_62(x: Any?) { + var z = null + if (x is Number? && x is Int? && x != z) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 63 +fun case_63(x: Any?, b: Boolean) { + val z1 = null + val z2 = null + val z3 = null + + if (x is Number?) { + if (x !== when (b) { true -> z1; false -> z2; else -> z3 }) { + if (x is Int?) { + x + x.equals(x) + } + } + } +} + +// TESTCASE NUMBER: 64 +fun case_64(x: Any?) { + if (x != try {implicitNullableNothingProperty} finally {}) { + if (x is Number) { + if (x is Int?) { + x + x.equals(x) + } + } + } +} + +// TESTCASE NUMBER: 65 +fun case_65(x: Any?, z: Nothing?) { + if (x is ClassLevel1?) { + if (x is ClassLevel2?) { + if (x is ClassLevel3?) { + if (x is ClassLevel4?) { + if (x is ClassLevel5?) { + if (x != z) { + x + x.equals(x) + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 66 +fun case_66(x: Any?, z1: Nothing?, z2: Nothing?, b: Boolean) { + if (x is ClassLevel1?) { + if (x is ClassLevel2?) { + if (x is ClassLevel3?) { + if (x != if (b) { z1 } else { z2 } && x is ClassLevel4?) { + if (x is ClassLevel5?) { + x + x.equals(x) + } + } + } + } + } +} + +// TESTCASE NUMBER: 67 +fun case_67(x: Any?) { + var z = null + + if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3?) { + if (x is ClassLevel4? && x != (fun (): Nothing? { return z })() && x is ClassLevel5?) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 68 +fun case_68(x: Any?, z: Nothing?) { + if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3?) { + if (x is ClassLevel4? && x != (fun (): Nothing? { return z })() && x is ClassLevel5?) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 69 +fun case_69(x: Any?, z: Nothing?) { + if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3? && x is ClassLevel4? && x != try { z } catch (e: Exception) { z } && x is ClassLevel5?) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 70 +fun case_70(x: Any?) { + if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3?) { + if (x is ClassLevel4?) { + + } else if (x is ClassLevel5? && x != nullableNothingProperty || x != implicitNullableNothingProperty) { + x + x.equals(x) + } + } else if (x is ClassLevel4? && x !== nullableNothingProperty && x is ClassLevel5?) { + x + x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 71 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_71(t: Any?) { + val z1 = null + var z2 = z1 + + if (t is Interface1?) { + if (t is Interface2?) { + if (t != z2) { + t + t.itest1() + t.itest2() + t.itest() + + t.let { it.itest1(); it.itest2() } + } + } + } +} + +/* + * TESTCASE NUMBER: 72 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362, KT-27032 + */ +fun case_72(t: Any?, z1: Nothing?) { + var z2 = null + + if (t is Interface1? && t != z1 ?: z2 && t is Interface2?) { + t + t.itest1() + t.itest2() + t.itest() + + t.let { it.itest1(); it.itest2() } + } +} + +/* + * TESTCASE NUMBER: 73 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_73(t: Any?) { + val `null` = null + + if (t is Interface2?) { + if (t is ClassLevel1?) { + if (t is ClassLevel2? && t is Interface1?) { + if (t !is Interface3?) {} else if (false) { + if (t != `null`) { + t.itest2() + t.itest1() + t.itest() + t.test1() + t.test2() + t + } + } + } + } + } +} + +/* + * TESTCASE NUMBER: 74 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_74(t: Any?) { + if (t is Interface2?) { + if (t is ClassLevel1?) { + if (t == implicitNullableNothingProperty || t === implicitNullableNothingProperty || t !is Interface1?) else { + if (t is ClassLevel2?) { + if (t is Interface3?) { + t.itest2() + t.itest1() + t.itest() + t.test1() + t.test2() + t + } + } + } + } + } +} + +/* + * TESTCASE NUMBER: 75 + * NOTE: lazy smartcasts + * DISCUSSION + * ISSUES: KT-28362 + */ +fun case_75(t: Any?, z: Nothing?) { + if (t !is ClassLevel2? || t !is ClassLevel1?) else { + if (t === ((((((z)))))) || t !is Interface1?) else { + if (t !is Interface2? || t !is Interface3?) {} else { + t.itest2() + t.itest1() + t.itest() + t.test1() + t.test2() + t + } + } + } +} + +// TESTCASE NUMBER: 76 +fun case_76(a: Any?, b: Int = if (a !is Number? === true || a !is Int? == true || a != null == false == true) 0 else a) { + a + b + b.equals(b) +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.7.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.7.kt new file mode 100644 index 00000000000..ea73ed5b10b --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.7.kt @@ -0,0 +1,354 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * NUMBER: 7 + * DESCRIPTION: Multi smartcasts + * UNEXPECTED BEHAVIOUR + * HELPERS: classes, enumClasses, objects, typealiases, properties + */ + +// FILE: other_package.kt + +package orherpackage + +// TESTCASE NUMBER: 13 +class EmptyClass13 {} + +// TESTCASE NUMBER: 14 +typealias TypealiasString14 = String? + +// FILE: main.kt + +import orherpackage.* + +// TESTCASE NUMBER: 1 +fun case_1(x: Any?) { + if (x != null || x != null || x != null || x != null || x != null || x != null || x != null) { + x + x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 2 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28159 + */ +fun case_2(x: Nothing?) { + if (x !== null && x !== null) { + x + } +} + +// TESTCASE NUMBER: 3 +fun case_3() { + if (Object.prop_1 == null && Object.prop_1 == null) + else { + Object.prop_1 + Object.prop_1.equals(Object.prop_1) + } +} + +// TESTCASE NUMBER: 4 +fun case_4(x: Char?) { + if (x != null && true || x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 5 +fun case_5() { + val x: Unit? = null + + if (x !== null || x !== null && x !== null || x !== null && x !== null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 6 +fun case_6(x: Class?) { + val y = true + + if (((false || x != null || false) && !y) || x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 7 +fun case_7() { + val x: EmptyObject? = null + if (x != null || x != null || x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: TypealiasString) { + if (x !== null && x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 9 +fun case_9(x: TypealiasNullableString?) { + if (x === null && x === null || x === null) { + + } else if (x === null || x === null) { + } else if (false) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 10 +fun case_10() { + val a = Class() + + if (a.prop_4 === null || a.prop_4 === null || true) { + if (a.prop_4 != null) { + a.prop_4 + a.prop_4.equals(a.prop_4) + } + } +} + +// TESTCASE NUMBER: 11 +fun case_11(x: TypealiasNullableString?, y: TypealiasNullableString) { + val t: TypealiasNullableString = null + + if (x == null) { + + } else { + if (x != null) { + if (y != null || y != null) { + if (stringProperty == null && nullableNothingProperty == null) { + if (t != null || t != null) { + x + x.equals(x) + } + } + } + } + } +} + +// TESTCASE NUMBER: 12 +fun case_12(x: TypealiasNullableString, y: TypealiasNullableString) = if (x == null) "1" + else if (y === null || y === null) { + x.equals(x) + x + } else "-1" + +// TESTCASE NUMBER: 13 +fun case_13(x: orherpackage.EmptyClass13?, y: Nothing?) = + if (x == null || x === y) { + throw Exception() + } else { + x.equals(x) + x + } + +// TESTCASE NUMBER: 14 +fun case_14() { + val a = Class() + if (a.prop_6 != a.prop_7) { + a.prop_6 + a.prop_6.equals(a.prop_6) + } +} + +// TESTCASE NUMBER: 15 +fun case_15(x: TypealiasString?) { + var y = null + val t = if (x === null || x == y && x === y) "" else { + x.equals(x) + x + } +} + +// TESTCASE NUMBER: 16 +fun case_16() { + val x: TypealiasNothing? = null + val y: Nothing? = null + + if (x != null || x !== null || x != y) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 17 +val case_17 = if (nullableIntProperty == null || nullableNothingProperty === nullableIntProperty) 0 else { + nullableIntProperty.equals(nullableIntProperty) + nullableIntProperty +} + +/* + * TESTCASE NUMBER: 18 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28328 + */ +fun case_18(a: DeepObject.A.B.C.D.E.F.G.J?, b: Nothing?) { + if (a != null || b !== a || false) { + a + a.equals(a) + } +} + +// TESTCASE NUMBER: 19 +fun case_19(b: Boolean) { + val a = if (b) { + object { + var y = null + val B19 = if (b) { + object { + val C19 = if (b) { + object { + val D19 = if (b) { + object { + val x: Number? = 10 + } + } else null + } + } else null + } + } else null + } + } else null + + if (a != null && a.B19 != a.y && a.B19.C19 != a.y && a.B19.C19.D19 != a.y && a.B19.C19.D19.x != a.y) { + a.B19.C19.D19.x + a.B19.C19.D19.x.equals(a.B19.C19.D19.x) + } +} + +// TESTCASE NUMBER: 20 +fun case_20(b: Boolean) { + val a = object { + val y = null + val B19 = object { + val C19 = object { + val D19 = if (b) { + object {} + } else null + } + } + } + + if (a.B19.C19.D19 !== null || a.y != a.B19.C19.D19) { + .B19..C19..D19. & case_20..B19..C19..D19.?")!>a.B19.C19.D19 + .B19..C19..D19."), DEBUG_INFO_SMARTCAST!>a.B19.C19.D19.equals(a.B19.C19.D19) + } +} + +// TESTCASE NUMBER: 21 +fun case_21() { + val y = null + if (EnumClassWithNullableProperty.A.prop_1 !== null && y != EnumClassWithNullableProperty.A.prop_1) { + EnumClassWithNullableProperty.A.prop_1 + EnumClassWithNullableProperty.A.prop_1.equals(EnumClassWithNullableProperty.A.prop_1) + } +} + +// TESTCASE NUMBER: 22 +fun case_22(a: (() -> Unit)?) { + var y = null + if (a != null || y != a) { + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a() + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a.equals(a) + } +} + +// TESTCASE NUMBER: 23 +fun case_23(a: ((Float) -> Int?)?, b: Float?, c: Nothing?) { + if (a != null && b !== null || a != c && b !== c) { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + if (x != null || c !== x) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 24 +fun case_24(a: ((() -> Unit) -> Unit)?, b: (() -> Unit)?) = + if (a !== null && b !== null || implicitNullableNothingProperty != a && nullableNothingProperty !== b) { + kotlin.Unit) -> kotlin.Unit)? & (() -> kotlin.Unit) -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a( kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>b) + kotlin.Unit) -> kotlin.Unit)? & (() -> kotlin.Unit) -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>a.equals(a) + kotlin.Unit)? & () -> kotlin.Unit"), DEBUG_INFO_SMARTCAST!>b.equals(b) + } else null + +// TESTCASE NUMBER: 25 +fun case_25(b: Boolean) { + val x = { + if (b) object { + val a = 10 + val b = null + } else null + } + + val y = if (b) x else null + + if (y !== null || x()!!.b != y) { + if (x()!!.b != y) { + val z = .?")!> case_25..?)? & () -> case_25..?"), DEBUG_INFO_SMARTCAST!>y() + + if (z != null) { + . & case_25..?"), DEBUG_INFO_SMARTCAST!>z.a + . & case_25..?"), DEBUG_INFO_SMARTCAST!>z.equals(z) + } + } + } +} + +// TESTCASE NUMBER: 26 +fun case_26(a: ((Float) -> Int?)?, b: Float?) { + var c: Nothing? = null + + if (a != null == true && b != null == true || c != a == true && b != c == true) { + val x = kotlin.Int?)? & (kotlin.Float) -> kotlin.Int?"), DEBUG_INFO_SMARTCAST!>a(b) + if (x != null == true) { + x + x.equals(x) + } + } +} + +// TESTCASE NUMBER: 27 +fun case_27(y: Nothing?) { + if (Object.prop_1 == null == true == true == true == true == true == true == true == true == true == true == true == true == true == true || y == Object.prop_1 == true == true == true == false == false) + else { + Object.prop_1 + Object.prop_1.equals(Object.prop_1) + } +} + +//TESTCASE NUMBER: 28 +fun case_28(a: DeepObject.A.B.C.D.E.F.G.J?) = + if (a != null == true == false == false == false == true == false == true == false == false == true == true && a.x !== nullableNothingProperty) { + a.x + a.equals(a) + } else -1 + +// TESTCASE NUMBER: 29 +fun case_29(a: Int?, b: Nothing?, c: Int = if (a === b) 0 else a) { + a + b +} + +// TESTCASE NUMBER: 30 +fun case_30(a: Int?, b: Nothing?, c: Int = if (a === b || a == null) 0 else a) { + a + b +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.8.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.8.kt new file mode 100644 index 00000000000..dd794ef7270 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.8.kt @@ -0,0 +1,128 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 8 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) using if expression and generic types. + * HELPERS: properties, classes + */ + +// TESTCASE NUMBER: 1 +fun case_1(x: Inv?) { + if (x != null) { + & Inv?")!>x + & Inv?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + } +} + +// TESTCASE NUMBER: 2 +fun case_2(a: Inv?>?>?>?>?>?) { + if (a != null) { + val b = ?>?>?>?>?> & Inv?>?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>a.get() + if (b != null) { + val c = ?>?>?>?> & Inv?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>b.get() + if (c != null) { + val d = ?>?>?> & Inv?>?>?>?"), DEBUG_INFO_SMARTCAST!>c.get() + if (d != null) { + val e = ?>?> & Inv?>?>?"), DEBUG_INFO_SMARTCAST!>d.get() + if (e != null) { + val f = ?> & Inv?>?"), DEBUG_INFO_SMARTCAST!>e.get() + if (f != null) { + val g = & Inv?"), DEBUG_INFO_SMARTCAST!>f.get() + if (g != null) { + g + g.equals(g) + } + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 3 +fun case_3(a: Inv?) { + if (a != null) { + val b = a + if (a == null) { + & Inv?")!>b + & Inv?"), DEBUG_INFO_SMARTCAST!>b.equals(b) + } + } +} + +// TESTCASE NUMBER: 4 +fun case_4(a: Inv?, b: Inv = if (a != null) & Inv?"), DEBUG_INFO_SMARTCAST!>a else Inv()) { + ?")!>a + ")!>b + ")!>b.equals(b) +} + +// TESTCASE NUMBER: 5 +fun case_5() { + if (nullableOut != null) { + & Out?")!>nullableOut + & Out?"), DEBUG_INFO_SMARTCAST!>nullableOut.equals(nullableOut) + } +} + +// TESTCASE NUMBER: 6 +fun case_6() { + val x: Inv? = null + + if (x != null) { + & Inv?")!>x + & Inv?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + } +} + +// TESTCASE NUMBER: 7 +fun case_7() { + var x: Inv? = null + + if (x != null) { + & Inv?")!>x + & Inv?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + } +} + +// TESTCASE NUMBER: 8 +fun case_8(x: ClassWithThreeTypeParameters?>?) { + if (x != null) { + ?> & ClassWithThreeTypeParameters?>?")!>x + ?> & ClassWithThreeTypeParameters?>?"), DEBUG_INFO_SMARTCAST!>x.equals(x) + if (x.x != null) { + x.x + x.x.equals(x.x) + } + if (x.y != null) { + x.y + x.y.equals(x.y) + } + if (x.z != null) { + & ClassWithThreeTypeParameters?")!>x.z + "), DEBUG_INFO_SMARTCAST!>x.z.equals(x.z) + if (x.z.x != null) { + x.z.x + x.z.x.equals(x.z.x) + } + if (x.z.y != null && x.z.z != null) { + x.z.y + x.z.y.equals(x.z.y) + x.z.z + x.z.z.equals(x.z.z) + } + } + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.9.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.9.kt new file mode 100644 index 00000000000..75596cba92f --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.9.kt @@ -0,0 +1,427 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-draft + * PLACE: type-inference, smart-casts, smart-casts-sources -> paragraph 4 -> sentence 1 + * RELEVANT PLACES: + * paragraph 1 -> sentence 2 + * paragraph 6 -> sentence 1 + * paragraph 9 -> sentence 3 + * paragraph 9 -> sentence 4 + * NUMBER: 9 + * DESCRIPTION: Smartcasts from nullability condition (value or reference equality) using if expression and generic types with projections. + * HELPERS: classes + */ + +// TESTCASE NUMBER: 1 +fun case_1(x: Out<out Int?>?) { + if (x != null) { + & Out?")!>x + & Out?")!>x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 2 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28598 + */ +fun case_2(a: Out<out Out<out Out<out Out<out Out<out Out<out Int?>?>?>?>?>?>?) { + if (a != null) { + val b = ?>?>?>?>?> & Out?>?>?>?>?>?")!>a.get() + if (b != null) { + val c = ?>?>?>?> & Out?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>b.get() + if (c != null) { + val d = ?>?>?> & Out?>?>?>?"), DEBUG_INFO_SMARTCAST!>c.get() + if (d != null) { + val e = ?>?> & Out?>?>?"), DEBUG_INFO_SMARTCAST!>d.get() + if (e != null) { + val f = ?> & Out?>?"), DEBUG_INFO_SMARTCAST!>e.get() + if (f != null) { + val g = & Out?"), DEBUG_INFO_SMARTCAST!>f.get() + if (g != null) { + g + g.equals(g) + } + } + } + } + } + } + } +} + +// TESTCASE NUMBER: 3 +fun case_3(a: Inv?) { + if (a != null) { + val b = a + if (a == null) + & Inv?")!>b + & Inv?")!>b.equals(b) + } +} + +// TESTCASE NUMBER: 4 +fun case_4(a: Out<out Int>?, b: Out<out Int> = if (a != null) & Out?"), DEBUG_INFO_SMARTCAST!>a else Out()) { + ?")!>a + ")!>b + ")!>b.equals(b) +} + +// TESTCASE NUMBER: 5 +val x: Out<out Int>? = null + +fun case_5() { + if (x != null) { + & Out?")!>x + & Out?")!>x.equals(x) + } +} + +// TESTCASE NUMBER: 6 +fun case_6() { + val x: Inv? = null + + if (x != null) { + & Inv?")!>x + & Inv?")!>x.equals(x) + } +} + +// TESTCASE NUMBER: 7 +fun case_7() { + var x: Out<out Int>? = null + + if (x != null) { + & Out?")!>x + & Out?")!>x.equals(x) + } +} + +/* + * TESTCASE NUMBER: 8 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-25432 + */ +fun case_8(x: ClassWithThreeTypeParameters?>?) { + if (x != null) { + ?> & ClassWithThreeTypeParameters?>?")!>x + ?> & ClassWithThreeTypeParameters?>?")!>x.equals(x) + if (x.x != null) { + x.x + x.x.equals(x.x) + } + if (x.y != null) { + x.y + x.y.equals(x.y) + } + if (x.z != null) { + ?")!>x.z + ?")!>x.z.equals(x.z) + if (x.z.x != null) { + x.z.x + x.z.x.equals(x.z.x) + } + if (x.z.y != null && x.z.z != null) { + x.z.y + x.z.z + x.z.y.equals(x.z.y) + x.z.z.equals(x.z.z) + } + } + } +} + +// TESTCASE NUMBER: 9 +fun case_9(a: (Inv) -> Inv?, b: Inv?) { + if (b != null) { + val c = a(b) + if (c != null) { + & Inv?")!>c + & Inv?")!>c.equals(c) + } + } +} + +// TESTCASE NUMBER: 10 +fun case_9(a: Inv<*>?) { + if (a != null) { + & Inv<*>?")!>a + & Inv<*>?")!>a.equals(a) + } +} + +// TESTCASE NUMBER: 11 +fun case_10() { + val a10: Out<*>? = null + + if (a10 != null) { + & Out<*>?")!>a10 + & Out<*>?")!>a10.equals(a10) + } +} + +// TESTCASE NUMBER: 12 +fun case_11() { + val a: In<*>? = null + + if (a != null) { + & In<*>?")!>a + & In<*>?")!>a.equals(a) + } +} + +// TESTCASE NUMBER: 13 +fun case_13(a: ClassWithSixTypeParameters<*, *, *, *, *, *>?) { + if (a != null) { + & ClassWithSixTypeParameters<*, *, *, *, *, *>?")!>a + & ClassWithSixTypeParameters<*, *, *, *, *, *>?")!>a.equals(a) + } +} + +// TESTCASE NUMBER: 14 +fun case_14(a: ClassWithSixTypeParameters<*, Int, *, Out<*>, *, Map>>?) { + if (a != null) { + , *, kotlin.collections.Map>> & ClassWithSixTypeParameters<*, kotlin.Int, *, Out<*>, *, kotlin.collections.Map>>?")!>a + , *, kotlin.collections.Map>> & ClassWithSixTypeParameters<*, kotlin.Int, *, Out<*>, *, kotlin.collections.Map>>?")!>a.equals(a) + } +} + +// TESTCASE NUMBER: 15 +fun case_15(a: Any?) { + if (a is ClassWithSixTypeParameters<*, *, *, *, *, *>?) { + if (a != null) { + a + & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>a.equals(a) + } + } +} + +// TESTCASE NUMBER: 16 +fun case_16(a: Any?) { + if (a === null) { + } else { + if (a !is ClassWithSixTypeParameters<*, *, *, *, *, *>?) { + } else { + & kotlin.Any & kotlin.Any?")!>a + & kotlin.Any?"), DEBUG_INFO_SMARTCAST!>a.equals(a) + } + } +} + +/* + * TESTCASE NUMBER: 17 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28598 + */ +fun case_17(a: Inv?>?>?>?>?>?) { + if (a != null) { + val b = ?>?>?>?>?> & Inv?>?>?>?>?>?")!>a.get() + if (b != null) { + val c = ?>?>?>?> & Out?>?>?>?>?"), DEBUG_INFO_SMARTCAST!>b.get() + if (c != null) { + val d = ?>?>?> & Out?>?>?>?"), DEBUG_INFO_SMARTCAST!>c.get() + if (d != null) { + val e = ?>?> & Out?>?>?"), DEBUG_INFO_SMARTCAST!>d.get() + if (e != null) { + val f = ?> & Out?>?"), DEBUG_INFO_SMARTCAST!>e.get() + if (f != null) { + val g = & Out?"), DEBUG_INFO_SMARTCAST!>f.get() + if (g != null) { + g + g.equals(g) + } + } + } + } + } + } + } +} + +/* + * TESTCASE NUMBER: 18 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_18(a: Inv) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +/* + * TESTCASE NUMBER: 19 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_19(a: Inv) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +/* + * TESTCASE NUMBER: 20 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_20(a: Inv) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +/* + * TESTCASE NUMBER: 21 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_21(a: Out<out Int?>) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +/* + * TESTCASE NUMBER: 22 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_22(a: Out<out Nothing?>) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +/* + * TESTCASE NUMBER: 23 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_23(a: Out<out Any?>) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +// TESTCASE NUMBER: 24 +fun case_24(a: Out) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +// TESTCASE NUMBER: 25 +fun case_25(a: Out) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +// TESTCASE NUMBER: 26 +fun case_26(a: Out) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +/* + * TESTCASE NUMBER: 27 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_27(a: Inv) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +/* + * TESTCASE NUMBER: 28 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_28(a: Inv) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +/* + * TESTCASE NUMBER: 29 + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-28785 + */ +fun case_29(a: Inv) { + if (a.x != null) { + a.x + a.x.equals(a.x) + } +} + +// TESTCASE NUMBER: 30 +fun case_30() { + val a = In() + val b = a.getWithUpperBoundT() + + if (b != null) { + b + b.equals(b) + } +} + +// TESTCASE NUMBER: 31 +fun case_31(y: Inv) { + val x = y.get() + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 32 +fun case_32(y: Inv) { + val x = y.getNullable() + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 33 +fun case_33(y: Inv) { + val x = y.getNullable() + + if (x != null) { + x + x.equals(x) + } +} + +// TESTCASE NUMBER: 34 +fun case_34(y: Inv) { + val x = y.getNullable() + + if (x != null) { + x + x.equals(x) + } +} diff --git a/compiler/tests-spec/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestSpecGenerated.java b/compiler/tests-spec/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestSpecGenerated.java index f3e5c2e0032..be8f962f1cc 100644 --- a/compiler/tests-spec/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestSpecGenerated.java +++ b/compiler/tests-spec/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestSpecGenerated.java @@ -803,6 +803,161 @@ public class DiagnosticsTestSpecGenerated extends AbstractDiagnosticsTestSpec { } } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-inference") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Type_inference extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInType_inference() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-inference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Smart_casts extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInSmart_casts() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Smart_casts_sources extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInSmart_casts_sources() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class P_4 extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInP_4() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Pos extends AbstractDiagnosticsTestSpec { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + @TestMetadata("1.1.kt") + public void test1_1() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.1.kt"); + } + + @TestMetadata("1.10.kt") + public void test1_10() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.10.kt"); + } + + @TestMetadata("1.11.kt") + public void test1_11() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.11.kt"); + } + + @TestMetadata("1.12.kt") + public void test1_12() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.12.kt"); + } + + @TestMetadata("1.13.kt") + public void test1_13() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.13.kt"); + } + + @TestMetadata("1.14.kt") + public void test1_14() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.14.kt"); + } + + @TestMetadata("1.15.kt") + public void test1_15() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.15.kt"); + } + + @TestMetadata("1.16.kt") + public void test1_16() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.16.kt"); + } + + @TestMetadata("1.17.kt") + public void test1_17() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.17.kt"); + } + + @TestMetadata("1.18.kt") + public void test1_18() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.18.kt"); + } + + @TestMetadata("1.2.kt") + public void test1_2() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.2.kt"); + } + + @TestMetadata("1.3.kt") + public void test1_3() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.3.kt"); + } + + @TestMetadata("1.4.kt") + public void test1_4() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.4.kt"); + } + + @TestMetadata("1.5.kt") + public void test1_5() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.5.kt"); + } + + @TestMetadata("1.6.kt") + public void test1_6() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.6.kt"); + } + + @TestMetadata("1.7.kt") + public void test1_7() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.7.kt"); + } + + @TestMetadata("1.8.kt") + public void test1_8() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.8.kt"); + } + + @TestMetadata("1.9.kt") + public void test1_9() throws Exception { + runTest("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos/1.9.kt"); + } + + public void testAllFilesPresentInPos() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-casts-sources/p-4/pos"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + } + } + } + } + } + @TestMetadata("compiler/tests-spec/testData/diagnostics/linked/when-expression") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)