Fix exception from InvokeProcessor when we get invoke from extension function type.

This commit is contained in:
Stanislav Erokhin
2015-12-11 13:55:59 +03:00
parent 616bb444ec
commit 39b6637c7c
4 changed files with 45 additions and 6 deletions
@@ -143,13 +143,11 @@ private fun ScopeTower.getExtensionInvokeCandidateDescriptor(
): CandidateWithBoundDispatchReceiver<FunctionDescriptor>? {
if (!KotlinBuiltIns.isExactExtensionFunctionType(extensionFunctionReceiver.type)) return null
return ReceiverScopeTowerLevel(this, extensionFunctionReceiver).getFunctions(OperatorNameConventions.INVOKE, null).single().let {
assert(it.diagnostics.isEmpty())
val synthesizedInvoke = createSynthesizedInvokes(listOf(it.descriptor)).single()
val invokeDescriptor = extensionFunctionReceiver.type.memberScope.getContributedFunctions(OperatorNameConventions.INVOKE, location).single()
val synthesizedInvoke = createSynthesizedInvokes(listOf(invokeDescriptor)).single()
// here we don't add SynthesizedDescriptor diagnostic because it should has priority as member
CandidateWithBoundDispatchReceiverImpl(extensionFunctionReceiver, synthesizedInvoke, listOf())
}
// here we don't add SynthesizedDescriptor diagnostic because it should has priority as member
return CandidateWithBoundDispatchReceiverImpl(extensionFunctionReceiver, synthesizedInvoke, listOf())
}
// case 1.(foo())() or (foo())()
@@ -0,0 +1,23 @@
class A(val x: (String.() -> Unit)?)
fun test(a: A) {
if (a.x != null) {
"".<!DEBUG_INFO_SMARTCAST!>(a.x)<!>()
a.<!UNSAFE_CALL!>x<!>("") // todo
<!DEBUG_INFO_SMARTCAST!>(a.x)<!>("")
}
"".<!UNSAFE_CALL!>(a.x)<!>()
a.<!UNSAFE_CALL!>x<!>("")
<!UNSAFE_CALL!>(a.x)<!>("")
with("") {
a.<!UNSAFE_CALL!>x<!>(<!NO_VALUE_FOR_PARAMETER!>)<!>
<!UNSAFE_CALL!>(a.x)<!>()
if (a.x != null) {
a.<!UNSAFE_CALL!>x<!>(<!NO_VALUE_FOR_PARAMETER!>)<!> // todo
<!DEBUG_INFO_SMARTCAST!>(a.x)<!>()
}
}
}
fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
@@ -0,0 +1,12 @@
package
public fun test(/*0*/ a: A): kotlin.Unit
public fun </*0*/ T, /*1*/ R> with(/*0*/ receiver: T, /*1*/ f: T.() -> R): R
public final class A {
public constructor A(/*0*/ x: (kotlin.String.() -> kotlin.Unit)?)
public final val x: (kotlin.String.() -> 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
}
@@ -13430,6 +13430,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("invokeAndSmartCast.kt")
public void testInvokeAndSmartCast() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt");
doTest(fileName);
}
@TestMetadata("invokeAsExtension.kt")
public void testInvokeAsExtension() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/invokeAsExtension.kt");