diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 567a0a484ee..79a8fe6f794 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -747,7 +747,9 @@ public class ExpressionCodegen extends KtVisitor impleme labelElement.getReferencedName().equals(loopBlockStackElement.targetLabel.getReferencedName())) { Label label = isBreak ? loopBlockStackElement.breakLabel : loopBlockStackElement.continueLabel; return StackValue.operation( - Type.VOID_TYPE, adapter -> { + Type.VOID_TYPE, + getNothingType(), + adapter -> { PseudoInsnsKt.fixStackAndJump(v, label); v.mark(afterBreakContinueLabel); return Unit.INSTANCE; @@ -1620,9 +1622,13 @@ public class ExpressionCodegen extends KtVisitor impleme } } + private KotlinType getNothingType() { + return state.getModule().getBuiltIns().getNothingType(); + } + @Override 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(); CallableMemberDescriptor descriptor = getContext().getContextDescriptor(); NonLocalReturnInfo nonLocalReturn = getNonLocalReturnInfo(descriptor, expression); @@ -4794,7 +4800,7 @@ public class ExpressionCodegen extends KtVisitor impleme @Override 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); v.athrow(); return Unit.INSTANCE; diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/UnsignedNumbersCoercion.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/UnsignedNumbersCoercion.kt index e1a5a6b9648..7d7a8f6e738 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/UnsignedNumbersCoercion.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/UnsignedNumbersCoercion.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.builtins.UnsignedType import org.jetbrains.kotlin.builtins.UnsignedTypes import org.jetbrains.kotlin.codegen.StackValue import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.typeUtil.isNothing import org.jetbrains.org.objectweb.asm.Type val StackValue.unsignedType: UnsignedType? @@ -22,8 +23,12 @@ fun coerceUnsignedToUInt( valueKotlinType: KotlinType?, uIntKotlinType: KotlinType ): StackValue { + stackValue.kotlinType?.let { + if (it.isNothing()) return stackValue + } + val valueUnsignedType = stackValue.unsignedType - ?: throw AssertionError("Unsigned type expected: $valueKotlinType") + ?: throw AssertionError("Unsigned type expected: ${stackValue.kotlinType}") if (valueUnsignedType == UnsignedType.UINT) return stackValue diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index e3fa3b2dc4b..9bae5638f20 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -21615,6 +21615,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT 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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/testData/codegen/box/ranges/unsigned/kt36953.kt b/compiler/testData/codegen/box/ranges/unsigned/kt36953.kt new file mode 100644 index 00000000000..0442b3e0a4c --- /dev/null +++ b/compiler/testData/codegen/box/ranges/unsigned/kt36953.kt @@ -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" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt b/compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt new file mode 100644 index 00000000000..98b3a7e636a --- /dev/null +++ b/compiler/testData/codegen/box/ranges/unsigned/kt36953_continue.kt @@ -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" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 8a0bc44b5f7..90cb06b11e4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -23131,6 +23131,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { 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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 868662ced4b..3b2cc70f24b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -21948,6 +21948,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes 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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 59fe159e191..45954ebe969 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -21615,6 +21615,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes 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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 51d71d4506b..b589bad8308 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -18381,6 +18381,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { 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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 2dba388cf79..62cb31dff3c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -18441,6 +18441,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { 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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)