KT-34500 Use correct loop parameter type in ForInArrayLoopGenerator

This commit is contained in:
Dmitry Petrov
2019-10-21 14:17:24 +03:00
parent bdc04547cc
commit 7dde503697
8 changed files with 137 additions and 2 deletions
@@ -84,8 +84,8 @@ class ForInArrayLoopGenerator(
v.load(arrayVar, OBJECT_TYPE)
v.load(indexVar, Type.INT_TYPE)
v.aload(arrayElParamType)
StackValue.onStack(arrayElParamType, elementType).put(asmElementType, elementType, codegen.v)
v.store(loopParameterVar, asmElementType)
StackValue.local(loopParameterVar, loopParameterType, loopParameterKotlinType)
.store(StackValue.onStack(arrayElParamType, elementType), v)
}
override fun checkPostConditionAndIncrement(loopExit: Label) {
@@ -0,0 +1,49 @@
fun box(): String {
testForInFloatArrayWithUpcastToAny()
testForInDoubleArrayWithUpcastToAny()
testForInDoubleArrayWithUpcastToComparable()
return "OK"
}
// NB JS: 1.0.toString() = "1"
// Thus we compare resulting string both with "1.0;2.0;3.0;" and "1;2;3;".
private fun testForInFloatArrayWithUpcastToAny() {
var test = ""
for (x: Any in floatArrayOf(1.0f, 2.0f, 3.0f)) {
test = "$test$x;"
useFloatAsAny(x)
}
if (test != "1.0;2.0;3.0;" && test != "1;2;3;") throw AssertionError(test)
}
private fun testForInDoubleArrayWithUpcastToAny() {
var test = ""
for (x: Any in doubleArrayOf(1.0, 2.0, 3.0)) {
test = "$test$x;"
useDoubleAsAny(x)
}
if (test != "1.0;2.0;3.0;" && test != "1;2;3;") throw AssertionError(test)
}
private fun testForInDoubleArrayWithUpcastToComparable() {
var test = ""
for (x: Comparable<*> in doubleArrayOf(1.0, 2.0, 3.0)) {
test = "$test$x;"
useDoubleAsComparable(x)
}
if (test != "1.0;2.0;3.0;" && test != "1;2;3;") throw AssertionError(test)
}
private fun useFloatAsAny(a: Any) {
a as Float
}
private fun useDoubleAsAny(a: Any) {
a as Double
}
private fun useDoubleAsComparable(a: Comparable<*>) {
a as Double
}
@@ -0,0 +1,36 @@
// !LANGUAGE: +InlineClasses
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
fun box(): String {
testForInUIntArrayWithUpcactToAny()
testForInUIntArrayWithUpcactToComparable()
return "OK"
}
fun testForInUIntArrayWithUpcactToAny() {
var test = ""
for (x: Any in uintArrayOf(1u, 2u, 3u)) {
test = "$test$x;"
useUIntAsAny(x)
}
if (test != "1;2;3;") throw AssertionError(test)
}
fun testForInUIntArrayWithUpcactToComparable() {
var test = ""
for (x: Comparable<*> in uintArrayOf(1u, 2u, 3u)) {
test = "$test$x;"
useUIntAsComparable(x)
}
if (test != "1;2;3;") throw AssertionError(test)
}
fun useUIntAsAny(a: Any) {
a as UInt
}
fun useUIntAsComparable(a: Comparable<*>) {
a as Comparable<*>
}
@@ -5218,11 +5218,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDelegatedPropertyUpdatedInLoopBody.kt");
}
@TestMetadata("forInDoubleArrayWithUpcast.kt")
public void testForInDoubleArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDoubleArrayWithUpcast.kt");
}
@TestMetadata("forInFieldUpdatedInLoopBody.kt")
public void testForInFieldUpdatedInLoopBody() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInFieldUpdatedInLoopBody.kt");
}
@TestMetadata("forInInlineClassArrayWithUpcast.kt")
public void testForInInlineClassArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInInlineClassArrayWithUpcast.kt");
}
@TestMetadata("forIntArray.kt")
public void testForIntArray() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forIntArray.kt");
@@ -5218,11 +5218,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDelegatedPropertyUpdatedInLoopBody.kt");
}
@TestMetadata("forInDoubleArrayWithUpcast.kt")
public void testForInDoubleArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDoubleArrayWithUpcast.kt");
}
@TestMetadata("forInFieldUpdatedInLoopBody.kt")
public void testForInFieldUpdatedInLoopBody() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInFieldUpdatedInLoopBody.kt");
}
@TestMetadata("forInInlineClassArrayWithUpcast.kt")
public void testForInInlineClassArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInInlineClassArrayWithUpcast.kt");
}
@TestMetadata("forIntArray.kt")
public void testForIntArray() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forIntArray.kt");
@@ -5188,11 +5188,21 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDelegatedPropertyUpdatedInLoopBody.kt");
}
@TestMetadata("forInDoubleArrayWithUpcast.kt")
public void testForInDoubleArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDoubleArrayWithUpcast.kt");
}
@TestMetadata("forInFieldUpdatedInLoopBody.kt")
public void testForInFieldUpdatedInLoopBody() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInFieldUpdatedInLoopBody.kt");
}
@TestMetadata("forInInlineClassArrayWithUpcast.kt")
public void testForInInlineClassArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInInlineClassArrayWithUpcast.kt");
}
@TestMetadata("forIntArray.kt")
public void testForIntArray() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forIntArray.kt");
@@ -4328,11 +4328,21 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDelegatedPropertyUpdatedInLoopBody.kt");
}
@TestMetadata("forInDoubleArrayWithUpcast.kt")
public void testForInDoubleArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDoubleArrayWithUpcast.kt");
}
@TestMetadata("forInFieldUpdatedInLoopBody.kt")
public void testForInFieldUpdatedInLoopBody() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInFieldUpdatedInLoopBody.kt");
}
@TestMetadata("forInInlineClassArrayWithUpcast.kt")
public void testForInInlineClassArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInInlineClassArrayWithUpcast.kt");
}
@TestMetadata("forIntArray.kt")
public void testForIntArray() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forIntArray.kt");
@@ -4338,11 +4338,21 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDelegatedPropertyUpdatedInLoopBody.kt");
}
@TestMetadata("forInDoubleArrayWithUpcast.kt")
public void testForInDoubleArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInDoubleArrayWithUpcast.kt");
}
@TestMetadata("forInFieldUpdatedInLoopBody.kt")
public void testForInFieldUpdatedInLoopBody() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInFieldUpdatedInLoopBody.kt");
}
@TestMetadata("forInInlineClassArrayWithUpcast.kt")
public void testForInInlineClassArrayWithUpcast() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forInInlineClassArrayWithUpcast.kt");
}
@TestMetadata("forIntArray.kt")
public void testForIntArray() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forInArray/forIntArray.kt");