FIR: Adjust testData for spec tests: other small things

This commit is contained in:
Denis Zharkov
2020-04-16 12:25:28 +03:00
parent 7c8e2724e1
commit 76bb45b46f
3 changed files with 185 additions and 0 deletions
@@ -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
}
}
}
@@ -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)
}
}
}