Always generate primitive boolean constants as expressions of type 'kotlin.Boolean'.

This commit is contained in:
Dmitry Petrov
2017-03-06 18:37:34 +03:00
parent 1bbbc1ca1c
commit cb61c358ea
4 changed files with 38 additions and 2 deletions
@@ -45,7 +45,7 @@ fun IrGeneratorContext.throwNpe(startOffset: Int, endOffset: Int, origin: IrStat
// a || b == if (a) true else b
fun IrGeneratorContext.oror(startOffset: Int, endOffset: Int, a: IrExpression, b: IrExpression, origin: IrStatementOrigin = IrStatementOrigin.OROR): IrWhen =
IrIfThenElseImpl(startOffset, endOffset, builtIns.booleanType,
a, IrConstImpl.constTrue(b.startOffset, b.endOffset, b.type), b,
a, IrConstImpl.constTrue(b.startOffset, b.endOffset, builtIns.booleanType), b,
origin)
fun IrGeneratorContext.oror(a: IrExpression, b: IrExpression, origin: IrStatementOrigin = IrStatementOrigin.OROR): IrWhen =
@@ -57,7 +57,7 @@ fun IrGeneratorContext.whenComma(a: IrExpression, b: IrExpression): IrWhen =
// a && b == if (a) b else false
fun IrGeneratorContext.andand(startOffset: Int, endOffset: Int, a: IrExpression, b: IrExpression, origin: IrStatementOrigin = IrStatementOrigin.ANDAND): IrWhen =
IrIfThenElseImpl(startOffset, endOffset, builtIns.booleanType,
a, b, IrConstImpl.constFalse(b.startOffset, b.endOffset, b.type),
a, b, IrConstImpl.constFalse(b.startOffset, b.endOffset, builtIns.booleanType),
origin)
fun IrGeneratorContext.andand(a: IrExpression, b: IrExpression, origin: IrStatementOrigin = IrStatementOrigin.ANDAND): IrWhen =
@@ -0,0 +1,7 @@
fun test1(b: Boolean) {
b && return
}
fun test2(b: Boolean) {
b || return
}
@@ -0,0 +1,23 @@
FILE /booleanConstsInAndAndOrOr.kt
FUN public fun test1(b: kotlin.Boolean): kotlin.Unit
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
WHEN type=kotlin.Boolean origin=ANDAND
BRANCH
if: GET_VAR 'value-parameter b: Boolean' type=kotlin.Boolean origin=null
then: RETURN type=kotlin.Nothing from='test1(Boolean): Unit'
GET_OBJECT 'Unit' type=kotlin.Unit
BRANCH
if: CONST Boolean type=kotlin.Boolean value='true'
then: CONST Boolean type=kotlin.Boolean value='false'
FUN public fun test2(b: kotlin.Boolean): kotlin.Unit
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
WHEN type=kotlin.Boolean origin=OROR
BRANCH
if: GET_VAR 'value-parameter b: Boolean' type=kotlin.Boolean origin=null
then: CONST Boolean type=kotlin.Boolean value='true'
BRANCH
if: CONST Boolean type=kotlin.Boolean value='true'
then: RETURN type=kotlin.Nothing from='test2(Boolean): Unit'
GET_OBJECT 'Unit' type=kotlin.Unit
@@ -416,6 +416,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
doTest(fileName);
}
@TestMetadata("booleanConstsInAndAndOrOr.kt")
public void testBooleanConstsInAndAndOrOr() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/expressions/booleanConstsInAndAndOrOr.kt");
doTest(fileName);
}
@TestMetadata("booleanOperators.kt")
public void testBooleanOperators() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/expressions/booleanOperators.kt");