KT-8011 Compiler crashes on attempt to create local class inside lambda

- use StackValue from upper-level context if local lookup fails

 #KT-8011 Fixed
This commit is contained in:
dnpetrov
2015-06-17 14:08:45 +03:00
parent dba29fff0d
commit 36ae8790a1
6 changed files with 97 additions and 4 deletions
@@ -2022,6 +2022,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return stackValueForLocal(descriptor, index);
}
return findCapturedValue(descriptor);
}
@Nullable
public StackValue findCapturedValue(@NotNull DeclarationDescriptor descriptor) {
if (context instanceof ConstructorContext) {
return lookupCapturedValueInConstructorParameters(descriptor);
}
@@ -159,10 +159,17 @@ public interface LocalLookup {
@NotNull
public StackValue outerValue(@NotNull EnclosedValueDescriptor d, @NotNull ExpressionCodegen codegen) {
int idx = codegen.lookupLocalIndex(d.getDescriptor());
assert idx != -1;
return StackValue.local(idx, d.getType());
DeclarationDescriptor declarationDescriptor = d.getDescriptor();
int idx = codegen.lookupLocalIndex(declarationDescriptor);
if (idx >= 0) {
return StackValue.local(idx, d.getType());
}
else {
assert declarationDescriptor != null : "No declaration descriptor for " + d;
StackValue capturedValue = codegen.findCapturedValue(declarationDescriptor);
assert capturedValue != null : "Unresolved captured value for " + d;
return capturedValue;
}
}
}
}