Fix for local closures
This commit is contained in:
@@ -40,6 +40,7 @@ import org.jetbrains.jet.codegen.state.GenerationState;
|
|||||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
@@ -1232,6 +1233,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
constructorContext.lookupInContext(descriptor, null, state, true);
|
constructorContext.lookupInContext(descriptor, null, state, true);
|
||||||
|
} else if (descriptor instanceof CallableMemberDescriptor) {
|
||||||
|
MutableClassDescriptor classDescriptor =
|
||||||
|
(MutableClassDescriptor) constructorContext.getParentContext().getContextDescriptor();
|
||||||
|
|
||||||
|
for (CallableMemberDescriptor memberDescriptor : classDescriptor.getAllCallableMembers()) {
|
||||||
|
if (descriptor.equals(memberDescriptor)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
constructorContext.lookupInContext(descriptor, null, state, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen.context;
|
package org.jetbrains.jet.codegen.context;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.codegen.OwnerKind;
|
import org.jetbrains.jet.codegen.OwnerKind;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
@@ -29,7 +31,7 @@ public class ConstructorContext extends MethodContext {
|
|||||||
public ConstructorContext(
|
public ConstructorContext(
|
||||||
ConstructorDescriptor contextDescriptor,
|
ConstructorDescriptor contextDescriptor,
|
||||||
OwnerKind kind,
|
OwnerKind kind,
|
||||||
CodegenContext parent
|
@NotNull CodegenContext parent
|
||||||
) {
|
) {
|
||||||
super(contextDescriptor, kind, parent);
|
super(contextDescriptor, kind, parent);
|
||||||
|
|
||||||
@@ -46,4 +48,11 @@ public class ConstructorContext extends MethodContext {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "Constructor: " + getContextDescriptor().getName();
|
return "Constructor: " + getContextDescriptor().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public CodegenContext getParentContext() {
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
return super.getParentContext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -816,6 +816,16 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
signatureWriter.writeAsmType(sharedVarType, false);
|
signatureWriter.writeAsmType(sharedVarType, false);
|
||||||
signatureWriter.writeParameterTypeEnd();
|
signatureWriter.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
|
else if (isLocalNamedFun(bindingContext, variableDescriptor)) {
|
||||||
|
Type type = classNameForAnonymousClass(
|
||||||
|
bindingContext,
|
||||||
|
(JetElement) BindingContextUtils.descriptorToDeclaration(bindingContext, variableDescriptor)
|
||||||
|
).getAsmType();
|
||||||
|
|
||||||
|
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
|
||||||
|
signatureWriter.writeAsmType(type, false);
|
||||||
|
signatureWriter.writeParameterTypeEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JetDelegatorToSuperCall superCall = closure.getSuperCall();
|
JetDelegatorToSuperCall superCall = closure.getSuperCall();
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
fun box(): String {
|
||||||
|
|
||||||
|
fun local():Int {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun test(): Int {
|
||||||
|
return local()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (A().test() == 10) "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fun box(): String {
|
||||||
|
|
||||||
|
fun local():Int {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
class A {
|
||||||
|
val test = local()
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (A().test == 10) "OK" else "fail"
|
||||||
|
}
|
||||||
@@ -951,6 +951,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
doTest("compiler/testData/codegen/box/closures/kt2151.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("localFunctionInFunction.kt")
|
||||||
|
public void testLocalFunctionInFunction() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/box/closures/localFunctionInFunction.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("localFunctionInInitializer.kt")
|
||||||
|
public void testLocalFunctionInInitializer() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/box/closures/localFunctionInInitializer.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("recursiveClosure.kt")
|
@TestMetadata("recursiveClosure.kt")
|
||||||
public void testRecursiveClosure() throws Exception {
|
public void testRecursiveClosure() throws Exception {
|
||||||
doTest("compiler/testData/codegen/box/closures/recursiveClosure.kt");
|
doTest("compiler/testData/codegen/box/closures/recursiveClosure.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user