KT-25907: Use proper loop parameter type in for-in-CharSequence

This commit is contained in:
Dmitry Petrov
2018-11-19 10:54:04 +03:00
parent b8086d9093
commit 9082f19c00
7 changed files with 39 additions and 2 deletions
@@ -81,8 +81,8 @@ class ForInCharSequenceLoopGenerator(
v.load(charSequenceVar, charSequenceType)
v.load(indexVar, Type.INT_TYPE)
v.invokeCharSequenceMethod("charAt", "(I)C")
StackValue.onStack(Type.CHAR_TYPE).put(asmElementType, elementType, codegen.v)
v.store(loopParameterVar, asmElementType)
StackValue.onStack(Type.CHAR_TYPE).put(loopParameterType, loopParameterKotlinType, codegen.v)
v.store(loopParameterVar, loopParameterType)
}
override fun checkPostConditionAndIncrement(loopExit: Label) {
@@ -0,0 +1,12 @@
// WITH_RUNTIME
fun box(): String {
val str = "abcd"
var r = ""
for (c: Char? in str) {
r = r + c ?: "?"
}
if (r != "abcd") throw AssertionError()
return "OK"
}
@@ -4605,6 +4605,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/controlStructures/forLoopMemberExtensionNext.kt");
}
@TestMetadata("forNullableCharInString.kt")
public void testForNullableCharInString() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forNullableCharInString.kt");
}
@TestMetadata("forUserType.kt")
public void testForUserType() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forUserType.kt");
@@ -4605,6 +4605,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/controlStructures/forLoopMemberExtensionNext.kt");
}
@TestMetadata("forNullableCharInString.kt")
public void testForNullableCharInString() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forNullableCharInString.kt");
}
@TestMetadata("forUserType.kt")
public void testForUserType() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forUserType.kt");
@@ -4605,6 +4605,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/controlStructures/forLoopMemberExtensionNext.kt");
}
@TestMetadata("forNullableCharInString.kt")
public void testForNullableCharInString() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forNullableCharInString.kt");
}
@TestMetadata("forUserType.kt")
public void testForUserType() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forUserType.kt");
@@ -4275,6 +4275,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/forLoopMemberExtensionNext.kt");
}
@TestMetadata("forNullableCharInString.kt")
public void testForNullableCharInString() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forNullableCharInString.kt");
}
@TestMetadata("forUserType.kt")
public void testForUserType() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forUserType.kt");
@@ -4305,6 +4305,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/controlStructures/forLoopMemberExtensionNext.kt");
}
@TestMetadata("forNullableCharInString.kt")
public void testForNullableCharInString() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forNullableCharInString.kt");
}
@TestMetadata("forUserType.kt")
public void testForUserType() throws Exception {
runTest("compiler/testData/codegen/box/controlStructures/forUserType.kt");