Fix inline class type coercion in == with generic call

#KT-27393 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2018-10-11 19:14:06 +03:00
parent 0201694f84
commit b7d7d1eb01
7 changed files with 67 additions and 3 deletions
@@ -3254,7 +3254,16 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
}
private StackValue genLazyUnlessProvided(@Nullable StackValue pregenerated, @NotNull KtExpression expr, @NotNull Type type) {
return pregenerated != null ? StackValue.coercion(pregenerated, type, null) : genLazy(expr, type);
return genLazyUnlessProvided(pregenerated, expr, type, null);
}
private StackValue genLazyUnlessProvided(
@Nullable StackValue pregenerated,
@NotNull KtExpression expr,
@NotNull Type type,
@Nullable KotlinType kotlinType
) {
return pregenerated != null ? StackValue.coercion(pregenerated, type, kotlinType) : genLazy(expr, type, kotlinType);
}
private StackValue genUnlessProvided(@Nullable StackValue pregenerated, @NotNull KtExpression expr, @NotNull Type type) {
@@ -3399,8 +3408,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
KotlinType leftKotlinType = kotlinType(left);
KotlinType rightKotlinType = kotlinType(right);
StackValue leftValue = genLazyUnlessProvided(pregeneratedSubject, left, leftType);
StackValue rightValue = genLazy(right, rightType);
StackValue leftValue = genLazyUnlessProvided(pregeneratedSubject, left, leftType, leftKotlinType);
StackValue rightValue = genLazy(right, rightType, rightKotlinType);
return StackValue.operation(Type.BOOLEAN_TYPE, v -> {
KotlinType nullableAnyType = state.getModule().getBuiltIns().getNullableAnyType();
@@ -0,0 +1,30 @@
inline class IcAny(val x: Any?)
inline class IcInt(val x: Int)
inline class IcLong(val x: Long)
fun <T> id(x: T) = x
fun box(): String {
if (IcInt(42) == id(IcInt(24))) return "Error 1"
if (IcInt(42) != id(IcInt(42))) return "Error 2"
if (id(IcInt(42)) == IcInt(24)) return "Error 3"
if (id(IcInt(42)) != IcInt(42)) return "Error 4"
if (id(IcInt(42)) == id(IcInt(24))) return "Error 5"
if (id(IcInt(42)) != id(IcInt(42))) return "Error 6"
if (IcLong(42) == id(IcLong(24))) return "Error 2, 1"
if (IcLong(42) != id(IcLong(42))) return "Error 2, 2"
if (id(IcLong(42)) == IcLong(24)) return "Error 2, 3"
if (id(IcLong(42)) != IcLong(42)) return "Error 2, 4"
if (id(IcLong(42)) == id(IcLong(24))) return "Error 2, 5"
if (id(IcLong(42)) != id(IcLong(42))) return "Error 2, 6"
if (IcAny(42) == id(IcAny(24))) return "Error 3, 1"
if (IcAny(42) != id(IcAny(42))) return "Error 3, 2"
if (id(IcAny(42)) == IcAny(24)) return "Error 3, 3"
if (id(IcAny(42)) != IcAny(42)) return "Error 3, 4"
if (id(IcAny(42)) == id(IcAny(24))) return "Error 3, 5"
if (id(IcAny(42)) != id(IcAny(42))) return "Error 3, 6"
return "OK"
}
@@ -11674,6 +11674,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/equalityForBoxesOfNullableValuesOfInlineClass.kt");
}
@TestMetadata("equalsOperatorWithGenericCall.kt")
public void testEqualsOperatorWithGenericCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/equalsOperatorWithGenericCall.kt");
}
@TestMetadata("extLambdaInInlineClassFun.kt")
public void testExtLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/extLambdaInInlineClassFun.kt");
@@ -11674,6 +11674,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/equalityForBoxesOfNullableValuesOfInlineClass.kt");
}
@TestMetadata("equalsOperatorWithGenericCall.kt")
public void testEqualsOperatorWithGenericCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/equalsOperatorWithGenericCall.kt");
}
@TestMetadata("extLambdaInInlineClassFun.kt")
public void testExtLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/extLambdaInInlineClassFun.kt");
@@ -11679,6 +11679,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/equalityForBoxesOfNullableValuesOfInlineClass.kt");
}
@TestMetadata("equalsOperatorWithGenericCall.kt")
public void testEqualsOperatorWithGenericCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/equalsOperatorWithGenericCall.kt");
}
@TestMetadata("extLambdaInInlineClassFun.kt")
public void testExtLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/extLambdaInInlineClassFun.kt");
@@ -10214,6 +10214,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/equalityForBoxesOfNullableValuesOfInlineClass.kt");
}
@TestMetadata("equalsOperatorWithGenericCall.kt")
public void testEqualsOperatorWithGenericCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/equalsOperatorWithGenericCall.kt");
}
@TestMetadata("extLambdaInInlineClassFun.kt")
public void testExtLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/extLambdaInInlineClassFun.kt");
@@ -11259,6 +11259,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/equalityForBoxesOfNullableValuesOfInlineClass.kt");
}
@TestMetadata("equalsOperatorWithGenericCall.kt")
public void testEqualsOperatorWithGenericCall() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/equalsOperatorWithGenericCall.kt");
}
@TestMetadata("extLambdaInInlineClassFun.kt")
public void testExtLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/extLambdaInInlineClassFun.kt");