[NI] Report unsafe implicit invoke accordingly to OI
There are several issues with unsafe desugaring for convention calls. Proper fix is not implemented here (see design proposal KT-30872). This commit only applies the old logic in the new inference. ^KT-30695 Fixed
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
class A(val x: (String.() -> Unit)?)
|
||||
|
||||
fun test(a: A) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
class A(val x: (String.() -> Unit)?)
|
||||
|
||||
fun test(a: A) {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class A {
|
||||
val lambda: () -> Unit = TODO()
|
||||
val memberInvoke: B = TODO()
|
||||
val extensionInvoke: C = TODO()
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke() {}
|
||||
}
|
||||
|
||||
class C
|
||||
operator fun C.invoke() {}
|
||||
|
||||
fun test(a: A?) {
|
||||
a?.lambda()
|
||||
a?.memberInvoke()
|
||||
a?.extensionInvoke()
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
class A {
|
||||
val lambda: () -> Unit = TODO()
|
||||
val memberInvoke: B = TODO()
|
||||
val extensionInvoke: C = TODO()
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke() {}
|
||||
}
|
||||
|
||||
class C
|
||||
operator fun C.invoke() {}
|
||||
|
||||
fun test(a: A?) {
|
||||
a?.<!UNSAFE_IMPLICIT_INVOKE_CALL!>lambda<!>()
|
||||
a?.<!UNSAFE_IMPLICIT_INVOKE_CALL!>memberInvoke<!>()
|
||||
a?.extensionInvoke()
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package
|
||||
|
||||
public fun test(/*0*/ a: A?): kotlin.Unit
|
||||
public operator fun C.invoke(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final val extensionInvoke: C
|
||||
public final val lambda: () -> kotlin.Unit
|
||||
public final val memberInvoke: B
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class B {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final operator fun invoke(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class C {
|
||||
public constructor C()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
class MemberInvokeOwner {
|
||||
operator fun invoke() {}
|
||||
}
|
||||
|
||||
class Cls {
|
||||
fun testImplicitReceiver() {
|
||||
<!INAPPLICABLE_CANDIDATE!>nullableExtensionProperty<!>()
|
||||
}
|
||||
}
|
||||
|
||||
val Cls.nullableExtensionProperty: MemberInvokeOwner?
|
||||
get() = null
|
||||
|
||||
val Cls.extensionProperty: MemberInvokeOwner
|
||||
get() = TODO()
|
||||
|
||||
fun testNullableReceiver(nullable: Cls?) {
|
||||
nullable?.extensionProperty()
|
||||
nullable.<!UNRESOLVED_REFERENCE!>extensionProperty<!>()
|
||||
}
|
||||
|
||||
fun testNotNullableReceiver(notNullable: Cls) {
|
||||
notNullable.<!INAPPLICABLE_CANDIDATE!>nullableExtensionProperty<!>()
|
||||
notNullable?.extensionProperty()
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
class MemberInvokeOwner {
|
||||
operator fun invoke() {}
|
||||
}
|
||||
|
||||
class Cls {
|
||||
fun testImplicitReceiver() {
|
||||
<!UNSAFE_IMPLICIT_INVOKE_CALL!>nullableExtensionProperty<!>()
|
||||
}
|
||||
}
|
||||
|
||||
val Cls.nullableExtensionProperty: MemberInvokeOwner?
|
||||
get() = null
|
||||
|
||||
val Cls.extensionProperty: MemberInvokeOwner
|
||||
get() = TODO()
|
||||
|
||||
fun testNullableReceiver(nullable: Cls?) {
|
||||
nullable?.<!UNSAFE_IMPLICIT_INVOKE_CALL!>extensionProperty<!>()
|
||||
nullable<!UNSAFE_CALL!>.<!><!FUNCTION_EXPECTED!>extensionProperty<!>()
|
||||
}
|
||||
|
||||
fun testNotNullableReceiver(notNullable: Cls) {
|
||||
notNullable.<!UNSAFE_IMPLICIT_INVOKE_CALL!>nullableExtensionProperty<!>()
|
||||
notNullable<!UNNECESSARY_SAFE_CALL!>?.<!>extensionProperty()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package
|
||||
|
||||
public val Cls.extensionProperty: MemberInvokeOwner
|
||||
public val Cls.nullableExtensionProperty: MemberInvokeOwner?
|
||||
public fun testNotNullableReceiver(/*0*/ notNullable: Cls): kotlin.Unit
|
||||
public fun testNullableReceiver(/*0*/ nullable: Cls?): kotlin.Unit
|
||||
|
||||
public final class Cls {
|
||||
public constructor Cls()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun testImplicitReceiver(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class MemberInvokeOwner {
|
||||
public constructor MemberInvokeOwner()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final operator fun invoke(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user