From d33d1367de26821795a2a6649e68069f8e558053 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Sat, 3 Dec 2011 18:22:18 +0200 Subject: [PATCH] KT-711 primitive value in left side of elvis operator --- .../src/org/jetbrains/jet/codegen/ExpressionCodegen.java | 6 ++++++ .../tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index c7f12d9cc34..0542a3bdbcf 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1693,6 +1693,12 @@ public class ExpressionCodegen extends JetVisitor { final Type exprType = expressionType(expression); final Type leftType = expressionType(expression.getLeft()); gen(expression.getLeft(), leftType); + if(leftType.getSort() != Type.OBJECT && leftType.getSort() != Type.ARRAY) { + if(leftType != exprType) { + StackValue.onStack(leftType).put(exprType, v); + } + return StackValue.onStack(exprType); + } v.dup(); Label end = new Label(); Label ifNull = new Label(); diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index 033f9c56b68..b9fc3be67c6 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -285,6 +285,12 @@ public class PrimitiveTypesTest extends CodegenTestCase { blackBoxFile("regressions/kt518.jet"); } + public void testKt711 () throws Exception { + loadText("fun box() = if ((1 ?: 0) == 1) \"OK\" else \"fail\""); +// System.out.println(generateToText()); + blackBox(); + } + public void testKt665() throws Exception { loadText("fun f(x: Long, zzz: Long = 1): Long\n" + "{\n" +