JVM: Handle inline class equality in when statement with declaration
#KT-34268 Fixed
This commit is contained in:
committed by
Alexander Udalov
parent
bbdbc2896b
commit
4878c7967a
@@ -3297,7 +3297,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
else if (opToken == KtTokens.EQEQ || opToken == KtTokens.EXCLEQ ||
|
||||
opToken == KtTokens.EQEQEQ || opToken == KtTokens.EXCLEQEQEQ) {
|
||||
return generateEquals(
|
||||
expression.getLeft(), expression.getRight(), opToken, null,
|
||||
expression.getLeft(), expression.getRight(), opToken, null, null,
|
||||
bindingContext.get(BindingContext.PRIMITIVE_NUMERIC_COMPARISON_INFO, expression)
|
||||
);
|
||||
}
|
||||
@@ -3372,6 +3372,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
@Nullable KtExpression right,
|
||||
@NotNull IElementType opToken,
|
||||
@Nullable StackValue pregeneratedSubject,
|
||||
@Nullable KotlinType subjectKotlinType,
|
||||
@Nullable PrimitiveNumericComparisonInfo primitiveNumericComparisonInfo
|
||||
) {
|
||||
if (left == null || right == null) {
|
||||
@@ -3382,7 +3383,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
});
|
||||
}
|
||||
|
||||
KotlinType leftKotlinType = kotlinType(left);
|
||||
KotlinType leftKotlinType = (subjectKotlinType != null) ? subjectKotlinType : kotlinType(left);
|
||||
KotlinType rightKotlinType = kotlinType(right);
|
||||
boolean leftIsInlineClass = leftKotlinType != null && InlineClassesUtilsKt.isInlineClassType(leftKotlinType);
|
||||
boolean rightIsInlineClass = rightKotlinType != null && InlineClassesUtilsKt.isInlineClassType(rightKotlinType);
|
||||
@@ -4892,10 +4893,10 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
return generateIsCheck(match, expression.getTypeReference(), expression.isNegated());
|
||||
}
|
||||
|
||||
private StackValue generateExpressionMatch(StackValue expressionToMatch, KtExpression subjectExpression, KtExpression patternExpression) {
|
||||
private StackValue generateExpressionMatch(StackValue expressionToMatch, KtExpression subjectExpression, KotlinType subjectKotlinType, KtExpression patternExpression) {
|
||||
if (expressionToMatch != null) {
|
||||
return generateEquals(
|
||||
subjectExpression, patternExpression, KtTokens.EQEQ, expressionToMatch,
|
||||
subjectExpression, patternExpression, KtTokens.EQEQ, expressionToMatch, subjectKotlinType,
|
||||
bindingContext.get(BindingContext.PRIMITIVE_NUMERIC_COMPARISON_INFO, patternExpression)
|
||||
);
|
||||
}
|
||||
@@ -4996,6 +4997,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
else {
|
||||
subjectLocal = -1;
|
||||
subjectType = Type.VOID_TYPE;
|
||||
subjectKotlinType = null;
|
||||
}
|
||||
|
||||
Label begin = new Label();
|
||||
@@ -5015,7 +5017,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
if (!whenEntry.isElse()) {
|
||||
KtWhenCondition[] conditions = whenEntry.getConditions();
|
||||
for (int i = 0; i < conditions.length; i++) {
|
||||
StackValue conditionValue = generateWhenCondition(subjectExpression, subjectType, subjectLocal, conditions[i]);
|
||||
StackValue conditionValue = generateWhenCondition(subjectExpression, subjectType, subjectKotlinType, subjectLocal, conditions[i]);
|
||||
BranchedValue.Companion.condJump(conditionValue, nextCondition, true, v);
|
||||
if (i < conditions.length - 1) {
|
||||
v.goTo(thisEntry);
|
||||
@@ -5069,7 +5071,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
}
|
||||
}
|
||||
|
||||
private StackValue generateWhenCondition(KtExpression subjectExpression, Type subjectType, int subjectLocal, KtWhenCondition condition) {
|
||||
private StackValue generateWhenCondition(KtExpression subjectExpression, Type subjectType, KotlinType subjectKotlinType, int subjectLocal, KtWhenCondition condition) {
|
||||
if (condition instanceof KtWhenConditionInRange) {
|
||||
KtWhenConditionInRange conditionInRange = (KtWhenConditionInRange) condition;
|
||||
return generateIn(StackValue.local(subjectLocal, subjectType),
|
||||
@@ -5083,7 +5085,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
}
|
||||
else if (condition instanceof KtWhenConditionWithExpression) {
|
||||
KtExpression patternExpression = ((KtWhenConditionWithExpression) condition).getExpression();
|
||||
return generateExpressionMatch(match, subjectExpression, patternExpression);
|
||||
return generateExpressionMatch(match, subjectExpression, subjectKotlinType, patternExpression);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("unsupported kind of when condition");
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
return when(val foo = 42UL) {
|
||||
42UL -> "OK"
|
||||
else -> "Fail"
|
||||
}
|
||||
}
|
||||
+5
@@ -12818,6 +12818,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt34268.kt")
|
||||
public void testKt34268() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mangledDefaultParameterFunction.kt")
|
||||
public void testMangledDefaultParameterFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
|
||||
|
||||
+5
@@ -12823,6 +12823,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt34268.kt")
|
||||
public void testKt34268() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mangledDefaultParameterFunction.kt")
|
||||
public void testMangledDefaultParameterFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
|
||||
|
||||
+5
@@ -11703,6 +11703,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28920_javaPrimitiveType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt34268.kt")
|
||||
public void testKt34268() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mangledDefaultParameterFunction.kt")
|
||||
public void testMangledDefaultParameterFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
|
||||
|
||||
Generated
+5
@@ -10098,6 +10098,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt34268.kt")
|
||||
public void testKt34268() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mangledDefaultParameterFunction.kt")
|
||||
public void testMangledDefaultParameterFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
|
||||
|
||||
+5
@@ -11253,6 +11253,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt28585.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt34268.kt")
|
||||
public void testKt34268() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/kt34268.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("mangledDefaultParameterFunction.kt")
|
||||
public void testMangledDefaultParameterFunction() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
|
||||
|
||||
Reference in New Issue
Block a user