Support bound references to objects and companion objects
Tweak member extension detection a little bit to prohibit extensions imported from objects (they don't have one of the receiver parameters)
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
// !CHECK_TYPE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
package test
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
fun foo(): String = "companion"
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
fun foo(): Int = 0
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val r1 = C::foo
|
||||
checkSubtype<(C) -> Int>(r1)
|
||||
|
||||
val r2 = test.C::foo
|
||||
checkSubtype<(C) -> Int>(r2)
|
||||
|
||||
val r3 = C.Companion::foo
|
||||
checkSubtype<() -> String>(r3)
|
||||
|
||||
val r4 = test.C.Companion::foo
|
||||
checkSubtype<() -> String>(r4)
|
||||
|
||||
val r5 = (C)::foo
|
||||
checkSubtype<() -> String>(r5)
|
||||
|
||||
val r6 = (test.C)::foo
|
||||
checkSubtype<() -> String>(r6)
|
||||
|
||||
val c = C.Companion
|
||||
val r7 = c::foo
|
||||
checkSubtype<() -> String>(r7)
|
||||
|
||||
C::<!UNRESOLVED_REFERENCE!>bar<!>
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package
|
||||
|
||||
package test {
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public final class C {
|
||||
public constructor C()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public final fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
object Obj {
|
||||
fun foo() {}
|
||||
val bar = 2
|
||||
}
|
||||
|
||||
fun test() {
|
||||
checkSubtype<() -> Unit>(Obj::foo)
|
||||
checkSubtype<() -> Int>(Obj::bar)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public object Obj {
|
||||
private constructor Obj()
|
||||
public final val bar: kotlin.Int = 2
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
import Obj.ext
|
||||
import A.Companion.ext2
|
||||
|
||||
object Obj {
|
||||
val String.ext: String get() = this
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
val String.ext2: String get() = this
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
String::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>ext<!>
|
||||
Obj::<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>ext<!>
|
||||
|
||||
String::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>ext2<!>
|
||||
A.Companion::<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>ext2<!>
|
||||
A::<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>ext2<!>
|
||||
|
||||
A::<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
A::<!UNRESOLVED_REFERENCE!>bar<!>
|
||||
}
|
||||
-4
@@ -10,10 +10,8 @@ public final class A {
|
||||
|
||||
public companion object Companion {
|
||||
private constructor Companion()
|
||||
public final val bar: kotlin.Int = 2
|
||||
public final val kotlin.String.ext2: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -21,10 +19,8 @@ public final class A {
|
||||
|
||||
public object Obj {
|
||||
private constructor Obj()
|
||||
public final val bar: kotlin.Int = 2
|
||||
public final val kotlin.String.ext: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
import Obj.ext
|
||||
import A.Companion.ext2
|
||||
|
||||
object Obj {
|
||||
fun foo() {}
|
||||
val bar = 2
|
||||
val String.ext: String get() = this
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo() {}
|
||||
val bar = 2
|
||||
val String.ext2: String get() = this
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
Obj::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>foo<!>
|
||||
Obj::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>bar<!>
|
||||
String::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>ext<!>
|
||||
|
||||
A.Companion::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>foo<!>
|
||||
A.Companion::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>bar<!>
|
||||
String::<!CALLABLE_REFERENCE_TO_OBJECT_MEMBER!>ext2<!>
|
||||
|
||||
A::<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
A::<!UNRESOLVED_REFERENCE!>bar<!>
|
||||
}
|
||||
Reference in New Issue
Block a user