KT-36953 break/continue/return/throw have kotlinType Nothing
This commit is contained in:
@@ -747,7 +747,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
labelElement.getReferencedName().equals(loopBlockStackElement.targetLabel.getReferencedName())) {
|
labelElement.getReferencedName().equals(loopBlockStackElement.targetLabel.getReferencedName())) {
|
||||||
Label label = isBreak ? loopBlockStackElement.breakLabel : loopBlockStackElement.continueLabel;
|
Label label = isBreak ? loopBlockStackElement.breakLabel : loopBlockStackElement.continueLabel;
|
||||||
return StackValue.operation(
|
return StackValue.operation(
|
||||||
Type.VOID_TYPE, adapter -> {
|
Type.VOID_TYPE,
|
||||||
|
getNothingType(),
|
||||||
|
adapter -> {
|
||||||
PseudoInsnsKt.fixStackAndJump(v, label);
|
PseudoInsnsKt.fixStackAndJump(v, label);
|
||||||
v.mark(afterBreakContinueLabel);
|
v.mark(afterBreakContinueLabel);
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
@@ -1620,9 +1622,13 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private KotlinType getNothingType() {
|
||||||
|
return state.getModule().getBuiltIns().getNothingType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue visitReturnExpression(@NotNull KtReturnExpression expression, StackValue receiver) {
|
public StackValue visitReturnExpression(@NotNull KtReturnExpression expression, StackValue receiver) {
|
||||||
return StackValue.operation(Type.VOID_TYPE, adapter -> {
|
return StackValue.operation(Type.VOID_TYPE, getNothingType(), adapter -> {
|
||||||
KtExpression returnedExpression = expression.getReturnedExpression();
|
KtExpression returnedExpression = expression.getReturnedExpression();
|
||||||
CallableMemberDescriptor descriptor = getContext().getContextDescriptor();
|
CallableMemberDescriptor descriptor = getContext().getContextDescriptor();
|
||||||
NonLocalReturnInfo nonLocalReturn = getNonLocalReturnInfo(descriptor, expression);
|
NonLocalReturnInfo nonLocalReturn = getNonLocalReturnInfo(descriptor, expression);
|
||||||
@@ -4794,7 +4800,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue visitThrowExpression(@NotNull KtThrowExpression expression, StackValue receiver) {
|
public StackValue visitThrowExpression(@NotNull KtThrowExpression expression, StackValue receiver) {
|
||||||
return StackValue.operation(Type.VOID_TYPE, adapter -> {
|
return StackValue.operation(Type.VOID_TYPE, getNothingType(), adapter -> {
|
||||||
gen(expression.getThrownExpression(), JAVA_THROWABLE_TYPE);
|
gen(expression.getThrownExpression(), JAVA_THROWABLE_TYPE);
|
||||||
v.athrow();
|
v.athrow();
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.builtins.UnsignedType
|
|||||||
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
||||||
import org.jetbrains.kotlin.codegen.StackValue
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
|
||||||
val StackValue.unsignedType: UnsignedType?
|
val StackValue.unsignedType: UnsignedType?
|
||||||
@@ -22,8 +23,12 @@ fun coerceUnsignedToUInt(
|
|||||||
valueKotlinType: KotlinType?,
|
valueKotlinType: KotlinType?,
|
||||||
uIntKotlinType: KotlinType
|
uIntKotlinType: KotlinType
|
||||||
): StackValue {
|
): StackValue {
|
||||||
|
stackValue.kotlinType?.let {
|
||||||
|
if (it.isNothing()) return stackValue
|
||||||
|
}
|
||||||
|
|
||||||
val valueUnsignedType = stackValue.unsignedType
|
val valueUnsignedType = stackValue.unsignedType
|
||||||
?: throw AssertionError("Unsigned type expected: $valueKotlinType")
|
?: throw AssertionError("Unsigned type expected: ${stackValue.kotlinType}")
|
||||||
|
|
||||||
if (valueUnsignedType == UnsignedType.UINT) return stackValue
|
if (valueUnsignedType == UnsignedType.UINT) return stackValue
|
||||||
|
|
||||||
|
|||||||
Generated
+10
@@ -21615,6 +21615,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953.kt")
|
||||||
|
public void testKt36953() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953_continue.kt")
|
||||||
|
public void testKt36953_continue() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// KJS_WITH_FULL_RUNTIME
|
||||||
|
|
||||||
|
fun testBreak() {
|
||||||
|
for (i in 0..1) {
|
||||||
|
for (j in break downTo 1u) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testReturn() {
|
||||||
|
for (i in 0..1) {
|
||||||
|
for (j in (return) downTo 1u) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testThrow() {
|
||||||
|
try {
|
||||||
|
for (i in 0..1) {
|
||||||
|
for (j in (throw Exception()) downTo 1u) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testBreak()
|
||||||
|
testReturn()
|
||||||
|
testThrow()
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// KJS_WITH_FULL_RUNTIME
|
||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// ^ TODO KT-37373
|
||||||
|
|
||||||
|
fun testContinue() {
|
||||||
|
for (i in 0..1) {
|
||||||
|
for (j in continue downTo 1u) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testContinue()
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+10
@@ -23131,6 +23131,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953.kt")
|
||||||
|
public void testKt36953() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953_continue.kt")
|
||||||
|
public void testKt36953_continue() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+10
@@ -21948,6 +21948,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953.kt")
|
||||||
|
public void testKt36953() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953_continue.kt")
|
||||||
|
public void testKt36953_continue() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+10
@@ -21615,6 +21615,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953.kt")
|
||||||
|
public void testKt36953() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953_continue.kt")
|
||||||
|
public void testKt36953_continue() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Generated
+10
@@ -18381,6 +18381,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953.kt")
|
||||||
|
public void testKt36953() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953_continue.kt")
|
||||||
|
public void testKt36953_continue() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+10
@@ -18441,6 +18441,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953.kt")
|
||||||
|
public void testKt36953() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt36953_continue.kt")
|
||||||
|
public void testKt36953_continue() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user