Fix codegen of !! for nullable generics

This commit is contained in:
Alexander Udalov
2013-02-06 17:20:47 +04:00
parent 75f09b7527
commit 433660b2ce
4 changed files with 46 additions and 14 deletions
@@ -2669,21 +2669,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@Override
public StackValue visitPostfixExpression(JetPostfixExpression expression, StackValue receiver) {
if (expression.getOperationReference().getReferencedNameElementType() == JetTokens.EXCLEXCL) {
JetExpression baseExpression = expression.getBaseExpression();
JetType type = bindingContext.get(BindingContext.EXPRESSION_TYPE, baseExpression);
StackValue base = genQualified(receiver, baseExpression);
if (type != null && type.isNullable()) {
base.put(base.type, v);
v.dup();
Label ok = new Label();
v.ifnonnull(ok);
v.invokestatic("jet/runtime/Intrinsics", "throwNpe", "()V");
v.mark(ok);
return StackValue.onStack(base.type);
}
else {
StackValue base = genQualified(receiver, expression.getBaseExpression());
if (isPrimitive(base.type)) {
return base;
}
base.put(base.type, v);
v.dup();
Label ok = new Label();
v.ifnonnull(ok);
v.invokestatic("jet/runtime/Intrinsics", "throwNpe", "()V");
v.mark(ok);
return StackValue.onStack(base.type);
}
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
if (op instanceof FunctionDescriptor) {