Fix for KT-14201: UnsupportedOperationException: Don't know how to generate outer expression for anonymous object with invoke and non-trivial closure

#KT-14201 Fixed
This commit is contained in:
Michael Bogdanov
2016-10-25 11:05:24 +03:00
parent e41cddd870
commit 1e59161e8f
5 changed files with 76 additions and 6 deletions
@@ -49,10 +49,7 @@ import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument;
import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument;
import org.jetbrains.kotlin.resolve.calls.model.*;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
@@ -1220,8 +1217,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
else if (descriptor instanceof CallableMemberDescriptor) {
ResolvedCall<? extends CallableDescriptor> call = CallUtilKt.getResolvedCall(expr, bindingContext);
if (call != null) {
lookupReceiver(call.getDispatchReceiver());
lookupReceiver(call.getExtensionReceiver());
lookupReceivers(call);
}
if (call instanceof VariableAsFunctionResolvedCall) {
lookupReceivers(((VariableAsFunctionResolvedCall) call).getVariableCall());
}
}
else if (descriptor instanceof VariableDescriptor) {
@@ -1234,6 +1233,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
}
private void lookupReceivers(@NotNull ResolvedCall<? extends CallableDescriptor> call) {
lookupReceiver(call.getDispatchReceiver());
lookupReceiver(call.getExtensionReceiver());
}
private void lookupReceiver(@Nullable ReceiverValue value) {
if (value instanceof ImplicitReceiver) {
if (value instanceof ExtensionReceiver) {
@@ -0,0 +1,15 @@
interface Intf {
val aValue: String
}
class ClassB {
val x = { "OK" }
val value: Intf = object : Intf {
override val aValue = x()
}
}
fun box() : String {
return ClassB().value.aValue
}
@@ -0,0 +1,27 @@
class A {
val z: String = "OK"
}
class B {
operator fun A.invoke(): String = z
}
class ClassB {
val x = A()
fun B.test(): String {
val value = object {
val z = x()
}
return value.z
}
fun call(): String {
return B().test()
}
}
fun box(): String {
return ClassB().call()
}
@@ -10006,6 +10006,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
doTest(fileName);
}
@TestMetadata("kt14201.kt")
public void testKt14201() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201.kt");
doTest(fileName);
}
@TestMetadata("kt14201_2.kt")
public void testKt14201_2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201_2.kt");
doTest(fileName);
}
@TestMetadata("kt4152.kt")
public void testKt4152() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt4152.kt");
@@ -10006,6 +10006,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt14201.kt")
public void testKt14201() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201.kt");
doTest(fileName);
}
@TestMetadata("kt14201_2.kt")
public void testKt14201_2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201_2.kt");
doTest(fileName);
}
@TestMetadata("kt4152.kt")
public void testKt4152() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt4152.kt");