Use proper type for context 'this'

Bug in 'generateThisOrOuterFromContext', it worked while instance of a
class was always an object.

 #KT-27078
This commit is contained in:
Dmitry Petrov
2018-09-24 12:33:51 +03:00
parent c1bb3479df
commit edc8cf3ed0
8 changed files with 76 additions and 3 deletions
@@ -1105,7 +1105,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
ClassDescriptor captureThis = closure.getCapturedOuterClassDescriptor();
if (captureThis != null) {
StackValue thisOrOuter = generateThisOrOuter(captureThis, false);
assert !isPrimitive(thisOrOuter.type) : "This or outer should be non primitive: " + thisOrOuter.type;
assert !isPrimitive(thisOrOuter.type) || captureThis.isInline() :
"This or outer for " + captureThis + " should be non-primitive: " + thisOrOuter.type;
callGenerator.putCapturedValueOnStack(thisOrOuter, thisOrOuter.type, paramIndex++);
}
}
@@ -2844,8 +2845,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
private StackValue generateThisOrOuterFromContext(@NotNull ClassDescriptor thisOrOuterClass, boolean isSuper, boolean forceOuter) {
CodegenContext cur = context;
SimpleType thisType = thisOrOuterClass.getDefaultType();
StackValue result = StackValue.local(0, asmType(thisType), thisType);
SimpleType contextType = cur.getThisDescriptor().getDefaultType();
StackValue result = StackValue.local(0, asmType(contextType), contextType);
boolean inStartConstructorContext = cur instanceof ConstructorContext;
while (cur != null) {
ClassDescriptor thisDescriptor = cur.getThisDescriptor();