Nullable function-like property call is prohibited now #KT-8252 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-01-12 12:13:12 +03:00
parent 0f80df7b2e
commit 1049d4c53a
7 changed files with 75 additions and 5 deletions
@@ -0,0 +1,7 @@
fun bar(doIt: Int.() -> Int) {
1.doIt()
1<!UNNECESSARY_SAFE_CALL!>?.<!>doIt()
val i: Int? = 1
i<!UNSAFE_CALL!>.<!>doIt()
i?.doIt()
}
@@ -0,0 +1,3 @@
package
public fun bar(/*0*/ doIt: kotlin.Int.() -> kotlin.Int): kotlin.Unit
+23
View File
@@ -0,0 +1,23 @@
class Rule(val apply:() -> Unit)
fun bar() {}
fun foo() {
val rule: Rule? = Rule { bar() }
// this compiles and works
val apply = rule?.apply
if (apply != null) <!DEBUG_INFO_SMARTCAST!>apply<!>()
// this compiles and works
rule?.apply?.invoke()
// this should be an error
rule?.<!UNSAFE_CALL!>apply<!>()
// these both also ok (with smart cast / unnecessary safe call)
if (rule != null) {
<!DEBUG_INFO_SMARTCAST!>rule<!>.apply()
rule<!UNNECESSARY_SAFE_CALL!>?.<!>apply()
}
}
+12
View File
@@ -0,0 +1,12 @@
package
public fun bar(): kotlin.Unit
public fun foo(): kotlin.Unit
public final class Rule {
public constructor Rule(/*0*/ apply: () -> kotlin.Unit)
public final val apply: () -> kotlin.Unit
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
}