Coerce loop body to Unit.
This commit is contained in:
+2
@@ -145,6 +145,8 @@ class InsertImplicitCasts(val builtIns: KotlinBuiltIns): IrElementTransformerVoi
|
||||
|
||||
loop.condition = loop.condition.cast(builtIns.booleanType)
|
||||
|
||||
loop.body = loop.body?.coerceToUnit(builtIns.unitType)
|
||||
|
||||
return loop
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = DoubleArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
FILE /coercionInLoop.kt
|
||||
FUN public fun box(): kotlin.String
|
||||
BLOCK_BODY
|
||||
VAR val a: kotlin.DoubleArray
|
||||
CALL 'constructor DoubleArray(Int)' type=kotlin.DoubleArray origin=null
|
||||
size: CONST Int type=kotlin.Int value='5'
|
||||
VAR val x: kotlin.collections.DoubleIterator
|
||||
CALL 'iterator(): DoubleIterator' type=kotlin.collections.DoubleIterator origin=null
|
||||
$this: GET_VAR 'a: DoubleArray' type=kotlin.DoubleArray origin=null
|
||||
VAR var i: kotlin.Int
|
||||
CONST Int type=kotlin.Int value='0'
|
||||
WHILE label=null origin=WHILE_LOOP
|
||||
condition: CALL 'hasNext(): Boolean' type=kotlin.Boolean origin=null
|
||||
$this: GET_VAR 'x: DoubleIterator' type=kotlin.collections.DoubleIterator origin=null
|
||||
body: TYPE_OP origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||
BLOCK type=kotlin.Int origin=null
|
||||
WHEN type=kotlin.Unit origin=IF
|
||||
if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
arg0: CALL 'get(Int): Double' type=kotlin.Double origin=GET_ARRAY_ELEMENT
|
||||
$this: GET_VAR 'a: DoubleArray' type=kotlin.DoubleArray origin=null
|
||||
index: GET_VAR 'i: Int' type=kotlin.Int origin=null
|
||||
arg1: CALL 'next(): Double' type=kotlin.Double origin=null
|
||||
$this: GET_VAR 'x: DoubleIterator' type=kotlin.collections.DoubleIterator origin=null
|
||||
then: RETURN type=kotlin.Nothing from='box(): String'
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
CONST String type=kotlin.String value='Fail '
|
||||
GET_VAR 'i: Int' type=kotlin.Int origin=null
|
||||
BLOCK type=kotlin.Int origin=POSTFIX_INCR
|
||||
VAR IR_TEMPORARY_VARIABLE val tmp0: kotlin.Int
|
||||
GET_VAR 'i: Int' type=kotlin.Int origin=POSTFIX_INCR
|
||||
SET_VAR 'i: Int' type=kotlin.Unit origin=POSTFIX_INCR
|
||||
CALL 'inc(): Int' type=kotlin.Int origin=POSTFIX_INCR
|
||||
$this: GET_VAR 'tmp0: Int' type=kotlin.Int origin=null
|
||||
GET_VAR 'tmp0: Int' type=kotlin.Int origin=null
|
||||
RETURN type=kotlin.Nothing from='box(): String'
|
||||
CONST String type=kotlin.String value='OK'
|
||||
@@ -715,4 +715,19 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/ir/irText/regressions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Regressions extends AbstractIrTextTestCase {
|
||||
public void testAllFilesPresentInRegressions() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/regressions"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("coercionInLoop.kt")
|
||||
public void testCoercionInLoop() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/regressions/coercionInLoop.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user