From db008d5d38dba6cf5a85e86fc8f3bbbe56d1b502 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 19 Jul 2012 21:12:58 +0400 Subject: [PATCH] KT-2466 "When" on boolean produces VerifyError #KT-2466 Fixed --- .../src/org/jetbrains/jet/codegen/ExpressionCodegen.java | 2 +- compiler/testData/codegen/patternMatching/kt2466.kt | 9 +++++++++ .../org/jetbrains/jet/codegen/PatternMatchingTest.java | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/patternMatching/kt2466.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 227253d510e..a7db4dead14 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -2855,7 +2855,7 @@ The "returned" value of try expression with no finally is either the last expres boolean patternIsNullable = false; JetType condJetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, condExpression); Type condType; - if (isNumberPrimitive(subjectType)) { + if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) { condType = asmType(condJetType); } else { diff --git a/compiler/testData/codegen/patternMatching/kt2466.kt b/compiler/testData/codegen/patternMatching/kt2466.kt new file mode 100644 index 00000000000..ba2e7dd052a --- /dev/null +++ b/compiler/testData/codegen/patternMatching/kt2466.kt @@ -0,0 +1,9 @@ +fun foo(b: Boolean) = + when (b) { + false -> 0 + true -> 1 + else -> 2 + } + +fun box(): String = if (foo(false) == 0 && foo(true) == 1) "OK" else "Fail" + diff --git a/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java b/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java index 4fcbd3b937f..f155c34376d 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java @@ -158,4 +158,8 @@ public class PatternMatchingTest extends CodegenTestCase { public void testNullableWhen() throws Exception { // KT-2148 blackBoxFile("patternMatching/nullableWhen.kt"); } + + public void testKt2466() throws Exception { + blackBoxFile("patternMatching/kt2466.kt"); + } }