diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-cast-sink-stability/p-5/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-cast-sink-stability/p-5/neg/1.1.fir.kt new file mode 100644 index 00000000000..d99c80f3ce9 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-cast-sink-stability/p-5/neg/1.1.fir.kt @@ -0,0 +1,43 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-268 + * PLACE: type-inference, smart-casts, smart-cast-sink-stability -> paragraph 5 -> sentence 1 + * RELEVANT PLACES: overload-resolution, building-the-overload-candidate-set-ocs, operator-call -> paragraph 4 -> sentence 1 + * overload-resolution, building-the-overload-candidate-set-ocs, operator-call -> paragraph 2 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: smart case for property `plus` available through the operator invoke + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-36876 + */ +// TESTCASE NUMBER: 1 +class Case1() { + + class E(val plus: Inv? = null, val value: Inv? = null) + + class Inv() { + operator fun invoke(value: Int) = Case1() + } + + fun foo(e: E) { + + if (e.plus != null) { + run { e + 1 } + + /* + [PROPERTY_AS_OPERATOR] (ok) + Properties cannot be used in operator conventions: 'invoke' in 'operatorCall.Case1.Inv' + [UNSAFE_OPERATOR_CALL] (nok) + Operator call corresponds to a dot-qualified call 'e.plus(1)' which is not allowed on a nullable receiver 'e'. + */ + e + 1 + + e.plus.invoke(1) //ok + } + + } +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-cast-sink-stability/p-5/pos/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-cast-sink-stability/p-5/pos/1.1.fir.kt new file mode 100644 index 00000000000..84e69888912 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/type-inference/smart-casts/smart-cast-sink-stability/p-5/pos/1.1.fir.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-268 + * PLACE: type-inference, smart-casts, smart-cast-sink-stability -> paragraph 5 -> sentence 1 + * RELEVANT PLACES: overload-resolution, building-the-overload-candidate-set-ocs, call-with-an-explicit-receiver -> paragraph 1 -> sentence 1 + * overload-resolution, building-the-overload-candidate-set-ocs, call-with-an-explicit-receiver -> paragraph 3 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: smart cast for the property available through the operator invoke + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-36876 + */ +// TESTCASE NUMBER: 1 +class Case1() { + + class E(val plus: Inv? = null, val value: Inv? = null) + + class Inv() { + operator fun invoke(value: Int) = Case1() + } + + fun foo(e: E) { + + if (e.value != null) { + run { e.value(1) } + /* + [UNSAFE_CALL] (nok) + Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Case1.Inv? + */ + e.value(1) + + } + } +} diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.fir.kt new file mode 100644 index 00000000000..fa0a164f4a2 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/notLinked/local-variables/type-parameters/neg/1.fir.kt @@ -0,0 +1,104 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE) + * + * SECTIONS: local-variables, type-parameters + * NUMBER: 1 + * DESCRIPTION: Local variables with forbidden type parameters. + * UNEXPECTED BEHAVIOUR + * ISSUES: KT-8341 + */ + +// TESTCASE NUMBER: 1 +fun case_1() { + val x1 = 1 + var x2 = 1 +} + +// TESTCASE NUMBER: 2 +fun case_2() { + val x1: Int = 1 + var x2: Int = 1 +} + +// TESTCASE NUMBER: 3 +fun case_3() { + val x1: Map = mapOf(1 to 1) + var x2: Map = mapOf(1 to 1) +} + +// TESTCASE NUMBER: 4 +fun case_4() { + val y1: Number where __UNRESOLVED__: __UNRESOLVED__ = 1 + var y2: Number where __UNRESOLVED__: __UNRESOLVED__ = 1 +} + +// TESTCASE NUMBER: 5 +fun case_5() { + val x1: Map = mapOf(1 to 1) + var x2: Map = mapOf(1 to 1) +} + +/* + * TESTCASE NUMBER: 6 + * UNEXPECTED BEHAVIOUR + */ +fun case_6() { + val (x1, y1) = Pair(1, 2) + var (x2, y2) = Pair(1, 2) +} + +/* + * TESTCASE NUMBER: 7 + * UNEXPECTED BEHAVIOUR + */ +fun case_7() { + val (x1, y1) where __UNRESOLVED__: __UNRESOLVED__ = Pair(1, 2) + var (x2, y2) where __UNRESOLVED__: __UNRESOLVED__ = Pair(1, 2) +} + +// TESTCASE NUMBER: 8 +fun case_8() { + val x1 = 1 + var x2 = 2 +} + +// TESTCASE NUMBER: 9 +fun case_9(y: Boolean?) = when (val x = y) { + true -> null + false -> null + null -> null +} + +// TESTCASE NUMBER: 10 +fun case_10(x: Boolean?) = when (val x where T: suspend () -> Unit, T: Boolean = x) { + true -> null + false -> null + null -> null +} + +// TESTCASE NUMBER: 11 +fun case_11() { + val x by lazy { 1 } + var x by lazy { 1 } +} + +// TESTCASE NUMBER: 12 +fun case_12() { + val x: Int + var x: Int +} + +// TESTCASE NUMBER: 13 +fun case_13() { + val x: Int where __UNRESOLVED__: __UNRESOLVED__ + var x: Int where __UNRESOLVED__: __UNRESOLVED__ +} + +// TESTCASE NUMBER: 14 +fun case_14() { + val x1 = 1 + var x2 = 1 +}