Forbid callable references to members and extensions with empty LHS
This syntax is reserved to be likely used in the future as a shorthand for "this::foo" where the resulting expression doesn't take the receiver as a parameter but has "this" already bound to it
This commit is contained in:
@@ -3,9 +3,9 @@ package test
|
||||
class A(val z: Int) {
|
||||
fun calc() = z
|
||||
|
||||
fun test() = call(A(z), ::calc)
|
||||
fun test() = call(A(z), A::calc)
|
||||
}
|
||||
|
||||
inline fun call(p: A, s: A.() -> Int): Int {
|
||||
return p.s()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
class A {
|
||||
fun foo(k: Int) = k
|
||||
|
||||
fun result() = (::foo)(this, 111)
|
||||
fun result() = (A::foo)(this, 111)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@ class A {
|
||||
fun k(k: Int) = k
|
||||
}
|
||||
|
||||
fun A.foo() = (::o)(this) + (A::k)(this, 222)
|
||||
fun A.foo() = (A::o)(this) + (A::k)(this, 222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().foo()
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class A {
|
||||
fun result() = (::foo)(this, "OK")
|
||||
fun result() = (A::foo)(this, "OK")
|
||||
}
|
||||
|
||||
fun A.foo(x: String) = x
|
||||
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ class A {
|
||||
val k = 222
|
||||
}
|
||||
|
||||
fun result() = (A::Inner)(this).o + (::Inner)(this).k
|
||||
fun result() = (A::Inner)(this).o + (A::Inner)(this).k
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@ class A {
|
||||
}
|
||||
}
|
||||
|
||||
fun A.foo() = (A::Inner)(this).o + (::Inner)(this).k
|
||||
fun A.foo() = (A::Inner)(this).o + (A::Inner)(this).k
|
||||
|
||||
fun box(): String {
|
||||
val result = A().foo()
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
class A {
|
||||
private fun foo() = "OK"
|
||||
|
||||
fun bar() = (::foo)(this)
|
||||
fun bar() = (A::foo)(this)
|
||||
}
|
||||
|
||||
fun box() = A().bar()
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ interface T {
|
||||
|
||||
class B : T {
|
||||
inner class C {
|
||||
fun bar() = (::foo)(this@B)
|
||||
fun bar() = (T::foo)(this@B)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ class Test {
|
||||
public fun exec() {
|
||||
val t = object : Thread() {
|
||||
override fun run() {
|
||||
::iv.get(this@Test)
|
||||
::iv.set(this@Test, 2)
|
||||
Test::iv.get(this@Test)
|
||||
Test::iv.set(this@Test, 2)
|
||||
}
|
||||
}
|
||||
t.start()
|
||||
|
||||
+4
-3
@@ -1,3 +1,4 @@
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
class K<in T : String> {
|
||||
@@ -6,10 +7,10 @@ class K<in T : String> {
|
||||
set(value) {}
|
||||
|
||||
fun run(): String {
|
||||
val p = ::t
|
||||
val p = K::class.memberProperties.single() as KMutableProperty1<K<String>, String>
|
||||
p.isAccessible = true
|
||||
p.set(this, "" as T)
|
||||
return p.get(this)
|
||||
p.set(this as K<String>, "")
|
||||
return p.get(this) as String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
val topLevelVal = 1
|
||||
fun topLevelFun() = 2
|
||||
|
||||
val A.extensionVal: Int get() = 3
|
||||
fun A.extensionFun(): Int = 4
|
||||
|
||||
class A {
|
||||
val memberVal = 5
|
||||
fun memberFun() = 6
|
||||
|
||||
val ok1 = ::topLevelVal
|
||||
val ok2 = ::topLevelFun
|
||||
|
||||
fun fail1() {
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>extensionVal<!>
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>extensionFun<!>
|
||||
}
|
||||
|
||||
fun fail2() {
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>memberVal<!>
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>memberFun<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
val ok1 = ::topLevelVal
|
||||
val ok2 = ::topLevelFun
|
||||
|
||||
fun A.fail1() {
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>extensionVal<!>
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>extensionFun<!>
|
||||
}
|
||||
|
||||
fun A.fail2() {
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>memberVal<!>
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>memberFun<!>
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package
|
||||
|
||||
public val ok1: kotlin.reflect.KProperty0<kotlin.Int>
|
||||
public val ok2: kotlin.reflect.KFunction0<kotlin.Int>
|
||||
public val topLevelVal: kotlin.Int = 1
|
||||
public val A.extensionVal: kotlin.Int
|
||||
public fun topLevelFun(): kotlin.Int
|
||||
public fun A.extensionFun(): kotlin.Int
|
||||
public fun A.fail1(): kotlin.Unit
|
||||
public fun A.fail2(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final val memberVal: kotlin.Int = 5
|
||||
public final val ok1: kotlin.reflect.KProperty0<kotlin.Int>
|
||||
public final val ok2: kotlin.reflect.KFunction0<kotlin.Int>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun fail1(): kotlin.Unit
|
||||
public final fun fail2(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public final fun memberFun(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
fun main() {
|
||||
val x = ::foo
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
}
|
||||
|
||||
fun A.foo() {}
|
||||
fun A.bar(<!UNUSED_PARAMETER!>x<!>: Int) {}
|
||||
fun A.baz() = "OK"
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package
|
||||
|
||||
public fun A.bar(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun A.baz(): kotlin.String
|
||||
public fun A.foo(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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 main(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A
|
||||
|
||||
fun A.main() {
|
||||
val x = ::foo
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
|
||||
fun A.foo() {}
|
||||
fun A.bar(<!UNUSED_PARAMETER!>x<!>: Int) {}
|
||||
fun A.baz() = "OK"
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package
|
||||
|
||||
public fun A.bar(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun A.baz(): kotlin.String
|
||||
public fun A.foo(): kotlin.Unit
|
||||
public fun A.main(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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
|
||||
}
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class B
|
||||
|
||||
class A {
|
||||
fun B.main() {
|
||||
val x = ::foo
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
}
|
||||
|
||||
fun A.foo() {}
|
||||
fun A.bar(<!UNUSED_PARAMETER!>x<!>: Int) {}
|
||||
fun A.baz() = "OK"
|
||||
Vendored
-20
@@ -1,20 +0,0 @@
|
||||
package
|
||||
|
||||
public fun A.bar(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public fun A.baz(): kotlin.String
|
||||
public fun A.foo(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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 fun B.main(): kotlin.Unit
|
||||
}
|
||||
|
||||
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
+2
-2
@@ -4,8 +4,8 @@ class A {
|
||||
fun A.extA(x: String) = x
|
||||
|
||||
fun main() {
|
||||
::<!MISSING_RECEIVER, EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>extInt<!>
|
||||
::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>extA<!>
|
||||
Int::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>extInt<!>
|
||||
A::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>extA<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-2
@@ -6,10 +6,9 @@ class A {
|
||||
inner class Inner
|
||||
|
||||
fun main() {
|
||||
val x = ::Inner
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>Inner<!>
|
||||
val y = A::Inner
|
||||
|
||||
checkSubtype<KFunction1<A, A.Inner>>(x)
|
||||
checkSubtype<KFunction1<A, Inner>>(y)
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-2
@@ -7,10 +7,9 @@ class A {
|
||||
}
|
||||
|
||||
fun A.main() {
|
||||
val x = ::Inner
|
||||
::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>Inner<!>
|
||||
val y = A::Inner
|
||||
|
||||
checkSubtype<KFunction1<A, A.Inner>>(x)
|
||||
checkSubtype<KFunction1<A, A.Inner>>(y)
|
||||
}
|
||||
|
||||
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
fun foo() {}
|
||||
fun bar(<!UNUSED_PARAMETER!>x<!>: Int) {}
|
||||
fun baz() = "OK"
|
||||
|
||||
fun main() {
|
||||
val x = ::foo
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final fun bar(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public final fun baz(): 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 final fun main(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
fun foo() {}
|
||||
fun bar(<!UNUSED_PARAMETER!>x<!>: Int) {}
|
||||
fun baz() = "OK"
|
||||
}
|
||||
|
||||
fun A.main() {
|
||||
val x = ::foo
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package
|
||||
|
||||
public fun A.main(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final fun bar(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public final fun baz(): 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
|
||||
}
|
||||
Vendored
-21
@@ -1,21 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
fun foo() {}
|
||||
fun bar(<!UNUSED_PARAMETER!>x<!>: Int) {}
|
||||
fun baz() = "OK"
|
||||
}
|
||||
|
||||
class B {
|
||||
fun A.main() {
|
||||
val x = ::foo
|
||||
val y = ::bar
|
||||
val z = ::baz
|
||||
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
checkSubtype<KFunction2<A, Int, Unit>>(y)
|
||||
checkSubtype<KFunction1<A, String>>(z)
|
||||
}
|
||||
}
|
||||
Vendored
-19
@@ -1,19 +0,0 @@
|
||||
package
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final fun bar(/*0*/ x: kotlin.Int): kotlin.Unit
|
||||
public final fun baz(): 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
|
||||
}
|
||||
|
||||
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
public final fun A.main(): kotlin.Unit
|
||||
}
|
||||
Vendored
+1
-1
@@ -8,7 +8,7 @@ class A {
|
||||
fun foo() {}
|
||||
|
||||
fun main() {
|
||||
val x = ::foo
|
||||
val x = ::<!CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS!>foo<!>
|
||||
|
||||
checkSubtype<KFunction1<A, Unit>>(x)
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ class A(var g: A) {
|
||||
val f: Int = 0
|
||||
|
||||
fun test() {
|
||||
val fRef: KProperty1<A, Int> = ::f
|
||||
val gRef: KMutableProperty1<A, A> = ::g
|
||||
val fRef: KProperty1<A, Int> = A::f
|
||||
val gRef: KMutableProperty1<A, A> = A::g
|
||||
}
|
||||
}
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
// !DIAGNOSTICS:-UNUSED_VARIABLE
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
fun test() {
|
||||
val fooRef: KProperty1<A, String> = ::foo
|
||||
val barRef: KMutableProperty1<A, Int> = ::bar
|
||||
}
|
||||
}
|
||||
|
||||
val A.foo: String get() = ""
|
||||
var A.bar: Int
|
||||
get() = 42
|
||||
set(value) { }
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package
|
||||
|
||||
public var A.bar: kotlin.Int
|
||||
public val A.foo: kotlin.String
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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 test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -6,7 +6,7 @@ class A(var g: A) {
|
||||
val f: Int = 0
|
||||
|
||||
fun test() {
|
||||
checkSubtype<KProperty1<A, Int>>(::f)
|
||||
checkSubtype<KMutableProperty1<A, A>>(::g)
|
||||
checkSubtype<KProperty1<A, Int>>(A::f)
|
||||
checkSubtype<KMutableProperty1<A, A>>(A::g)
|
||||
}
|
||||
}
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
val foo: Unit = Unit
|
||||
var bar: String = ""
|
||||
var self: A
|
||||
get() = this
|
||||
set(value) { }
|
||||
}
|
||||
|
||||
fun A.test() {
|
||||
val x = ::foo
|
||||
val y = ::bar
|
||||
val z = ::self
|
||||
|
||||
checkSubtype<KProperty1<A, Unit>>(x)
|
||||
checkSubtype<KMutableProperty1<A, String>>(y)
|
||||
checkSubtype<KMutableProperty1<A, A>>(z)
|
||||
|
||||
y.set(z.get(A()), x.get(A()).toString())
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package
|
||||
|
||||
public fun A.test(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final var bar: kotlin.String
|
||||
public final val foo: kotlin.Unit
|
||||
public final var self: A
|
||||
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
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
>>> val foo = "REPL"
|
||||
>>> ::foo.name
|
||||
foo
|
||||
>>> ::
|
||||
... foo.name
|
||||
foo
|
||||
Reference in New Issue
Block a user