[FE] Fix positioning strategy for SAFE_CALL_WILL_CHANGE_NULLABILITY warning

^KT-46860
This commit is contained in:
Dmitriy Novozhilov
2022-03-28 11:28:08 +04:00
committed by teamcity
parent 565c61a702
commit 078acb1bfe
16 changed files with 127 additions and 7 deletions
@@ -4,5 +4,5 @@
fun ff() {
val i: Int = 1
val a: Int = <!SAFE_CALL_WILL_CHANGE_NULLABILITY!>i<!UNNECESSARY_SAFE_CALL!>?.<!>plus(2)<!>
val a: Int = i<!SAFE_CALL_WILL_CHANGE_NULLABILITY!><!UNNECESSARY_SAFE_CALL!>?.<!>plus(2)<!>
}
@@ -8,6 +8,6 @@ fun foo(): String {
}
fun bar(): String {
val x = fn() ?: return ""
val y = <!SAFE_CALL_WILL_CHANGE_NULLABILITY!>x<!UNNECESSARY_SAFE_CALL!>?.<!>let { throw Exception() }<!> <!USELESS_ELVIS!>?: "unreachable"<!>
val y = x<!SAFE_CALL_WILL_CHANGE_NULLABILITY!><!UNNECESSARY_SAFE_CALL!>?.<!>let { throw Exception() }<!> <!USELESS_ELVIS!>?: "unreachable"<!>
return y
}
@@ -8,6 +8,6 @@ fun foo(): String {
}
fun bar(): String {
val x = fn() ?: return ""
<!UNREACHABLE_CODE!>val <!UNUSED_VARIABLE!>y<!> =<!> <!SAFE_CALL_WILL_CHANGE_NULLABILITY!>x<!UNNECESSARY_SAFE_CALL!>?.<!>let { throw Exception() }<!> <!UNREACHABLE_CODE, USELESS_ELVIS!>?: "unreachable"<!>
<!UNREACHABLE_CODE!>val <!UNUSED_VARIABLE!>y<!> =<!> x<!SAFE_CALL_WILL_CHANGE_NULLABILITY!><!UNNECESSARY_SAFE_CALL!>?.<!>let { throw Exception() }<!> <!UNREACHABLE_CODE, USELESS_ELVIS!>?: "unreachable"<!>
<!UNREACHABLE_CODE!>return y<!>
}
@@ -0,0 +1,35 @@
// FIR_IDENTICAL
// LANGUAGE: -SafeCallsAreAlwaysNullable
// DIAGNOSTICS: -UNNECESSARY_SAFE_CALL
// ISSUE: KT-46860
interface A {
fun id(): A
fun foo(): String
}
fun test_1(a: A) {
val s = a.id().id().id().id().id().id().id().id()<!SAFE_CALL_WILL_CHANGE_NULLABILITY!>?.foo()<!>.length
}
fun test_2(a: A) {
val s = a.id()
.id()
.id()
.id()
<!SAFE_CALL_WILL_CHANGE_NULLABILITY!>?.id()<!>
.id()
.id()
.id()
<!SAFE_CALL_WILL_CHANGE_NULLABILITY!>?.foo()<!>
<!SAFE_CALL_WILL_CHANGE_NULLABILITY!>?.length<!>
}
fun test_3(a: A) {
val s = a.id()<!SAFE_CALL_WILL_CHANGE_NULLABILITY!>?.
id()<!>.
id()<!SAFE_CALL_WILL_CHANGE_NULLABILITY!>?.
foo()<!>.
length
}
@@ -0,0 +1,13 @@
package
public fun test_1(/*0*/ a: A): kotlin.Unit
public fun test_2(/*0*/ a: A): kotlin.Unit
public fun test_3(/*0*/ a: A): kotlin.Unit
public interface A {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract fun id(): A
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}