KT-36953 break/continue/return/throw have kotlinType Nothing

This commit is contained in:
Dmitry Petrov
2020-03-10 11:08:17 +03:00
parent 603685b5a4
commit e175ff0d73
10 changed files with 122 additions and 4 deletions
@@ -747,7 +747,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> 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<StackValue, StackValue> 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<StackValue, StackValue> 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;
@@ -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