NI: don't do substitution for unsupported callable descriptors to use as callable references

^KT-41729 Fixed
This commit is contained in:
Victor Petukhov
2020-09-09 11:55:18 +03:00
parent 668098f3a8
commit 685d16ec68
27 changed files with 247 additions and 55 deletions
@@ -0,0 +1,8 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun a() {
val x = 10
foo(::x)
}
fun foo(a: Any) {}
@@ -0,0 +1,8 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun a() {
val x = 10
foo(::<!UNSUPPORTED!>x<!>)
}
fun foo(a: Any) {}
@@ -0,0 +1,4 @@
package
public fun a(): kotlin.Unit
public fun foo(/*0*/ a: kotlin.Any): kotlin.Unit
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun eat(value: Any) {}
fun test(param: String) {
val a = ::param
val local = "local"
val b = ::local
val lambda = { -> }
val g = ::lambda
eat(::param)
}
@@ -0,0 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun eat(value: Any) {}
fun test(param: String) {
val a = ::<!UNSUPPORTED!>param<!>
val local = "local"
val b = ::<!UNSUPPORTED!>local<!>
val lambda = { -> }
val g = ::<!UNSUPPORTED!>lambda<!>
eat(::<!UNSUPPORTED!>param<!>)
}
@@ -0,0 +1,4 @@
package
public fun eat(/*0*/ value: kotlin.Any): kotlin.Unit
public fun test(/*0*/ param: kotlin.String): kotlin.Unit
@@ -0,0 +1,14 @@
// Issue: KT-41729
import kotlin.reflect.KProperty
class Foo {
operator fun <T> getValue(thisRef: Any?, property: KProperty<*>) = 1
}
fun main() {
val f = Foo()
val a: Int
<!VARIABLE_EXPECTED!>get()<!> = f.getValue(null, ::a) // no exception after fix
<!UNRESOLVED_REFERENCE!>print<!>(<!UNINITIALIZED_VARIABLE!>a<!>)
}
@@ -0,0 +1,14 @@
// Issue: KT-41729
import kotlin.reflect.KProperty
class Foo {
operator fun <T> getValue(thisRef: Any?, property: KProperty<*>) = 1
}
fun main() {
val f = Foo()
val a: Int
<!UNRESOLVED_REFERENCE!>get<!>() = f.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getValue<!>(null, ::<!UNSUPPORTED!>a<!>) // no exception after fix
<!UNRESOLVED_REFERENCE!>print<!>(<!UNINITIALIZED_VARIABLE!>a<!>)
}
@@ -0,0 +1,11 @@
package
public fun main(): kotlin.Unit
public final class Foo {
public constructor Foo()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun </*0*/ T> getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,14 @@
// Issue: KT-41729
import kotlin.reflect.KProperty
class Foo {
operator fun <T> getValue(thisRef: Any?, property: KProperty<*>) = 1
}
fun main(x: Int) {
val f = Foo()
val a: Int
<!VARIABLE_EXPECTED!>get()<!> = f.getValue(null, ::x) // no exception after fix
<!UNRESOLVED_REFERENCE!>print<!>(<!UNINITIALIZED_VARIABLE!>a<!>)
}
@@ -0,0 +1,14 @@
// Issue: KT-41729
import kotlin.reflect.KProperty
class Foo {
operator fun <T> getValue(thisRef: Any?, property: KProperty<*>) = 1
}
fun main(<!UNUSED_PARAMETER!>x<!>: Int) {
val f = Foo()
val a: Int
<!UNRESOLVED_REFERENCE!>get<!>() = f.<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getValue<!>(null, ::<!UNSUPPORTED!>x<!>) // no exception after fix
<!UNRESOLVED_REFERENCE!>print<!>(<!UNINITIALIZED_VARIABLE!>a<!>)
}
@@ -0,0 +1,11 @@
package
public fun main(/*0*/ x: kotlin.Int): kotlin.Unit
public final class Foo {
public constructor Foo()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final operator fun </*0*/ T> getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ property: kotlin.reflect.KProperty<*>): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,19 @@
// FILE: Customer.java
public class Customer {
private String name;
public Customer(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
// FILE: test.kt
val customerName = Customer::name
@@ -0,0 +1,19 @@
// FILE: Customer.java
public class Customer {
private String name;
public Customer(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
// FILE: test.kt
val customerName = Customer::<!UNSUPPORTED!>name<!>
@@ -0,0 +1,13 @@
package
public val customerName: kotlin.reflect.KMutableProperty1<Customer, kotlin.String!>
public open class Customer {
public constructor Customer(/*0*/ name: kotlin.String!)
private final var name: kotlin.String!
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun getName(): kotlin.String!
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open fun setName(/*0*/ name: kotlin.String!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}