Don't treat values of type "Unit?" to be always equal to Unit.VALUE

Two changes here: StackValue.Constant does cast iff value is non-null (if null,
no cast between classes is really needed, as null can be an instance of
anything), and codegen for safe qualified expressions uses correct type for the
expression

 #KT-4265 Fixed
This commit is contained in:
Alexander Udalov
2013-12-04 19:13:39 +04:00
parent 96f753278c
commit f19ede0637
5 changed files with 49 additions and 3 deletions
@@ -2622,13 +2622,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
public StackValue visitSafeQualifiedExpression(@NotNull JetSafeQualifiedExpression expression, StackValue unused) {
JetExpression receiver = expression.getReceiverExpression();
JetExpression selector = expression.getSelectorExpression();
Type type = boxType(expressionType(expression));
Type receiverType = expressionType(receiver);
gen(receiver, receiverType);
if (isPrimitive(receiverType)) {
StackValue propValue = genQualified(StackValue.onStack(receiverType), selector);
Type type = boxType(propValue.type);
propValue.put(type, v);
return StackValue.onStack(type);
@@ -2639,7 +2639,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
v.dup();
v.ifnull(ifnull);
StackValue propValue = genQualified(StackValue.onStack(receiverType), selector);
Type type = boxType(propValue.type);
propValue.put(type, v);
v.goTo(end);
@@ -430,7 +430,10 @@ public abstract class StackValue {
else {
v.aconst(value);
}
coerceTo(type, v);
if (value != null) {
coerceTo(type, v);
}
}
@Override