[JS IR] Fix unsgined integer default arguemtns (KT-44180)

Const lowering didn't exprect null constants with unsigned number
types and crashed with NPE. This commit fixes that.
This commit is contained in:
Svyatoslav Kuzmich
2021-01-11 17:00:05 +03:00
parent 0110b4e4b4
commit 2d88ff6fb2
10 changed files with 61 additions and 1 deletions
@@ -32343,6 +32343,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/defaultArguments.kt");
}
@TestMetadata("equalsImplForInlineClassWrappingNullableInlineClass.kt")
public void testEqualsImplForInlineClassWrappingNullableInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");
@@ -45,7 +45,7 @@ class ConstTransformer(private val context: JsIrBackendContext) : IrElementTrans
override fun <T> visitConst(expression: IrConst<T>): IrExpression {
with(context.intrinsics) {
if (expression.type.isUnsigned()) {
if (expression.type.isUnsigned() && expression.kind != IrConstKind.Null) {
return when (expression.type.classifierOrNull) {
uByteClassSymbol -> lowerConst(uByteClassSymbol, IrConstImpl.Companion::byte, IrConstKind.Byte.valueOf(expression))
@@ -0,0 +1,20 @@
// WITH_RUNTIME
// Case of KT-44180
fun foo(
p0: UByte = 1u,
p1: UShort = 1u,
p2: UInt = 1u,
p4: ULong = 1uL,
): ULong {
return p0.toULong() + p1.toUShort() + p2.toUInt() + p4
}
fun box(): String {
if (foo() != 4uL) return "Fail 1"
if (foo(p2 = 10u) != 13uL) return "Fail 2"
if (foo(10u, 10u, 10u, 10uL) != 40uL) return "Fail 3"
return "OK"
}
@@ -32709,6 +32709,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/defaultArguments.kt");
}
@TestMetadata("equalsImplForInlineClassWrappingNullableInlineClass.kt")
public void testEqualsImplForInlineClassWrappingNullableInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");
@@ -30348,6 +30348,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/defaultArguments.kt");
}
@TestMetadata("equalsImplForInlineClassWrappingNullableInlineClass.kt")
public void testEqualsImplForInlineClassWrappingNullableInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");
@@ -32343,6 +32343,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/defaultArguments.kt");
}
@TestMetadata("equalsImplForInlineClassWrappingNullableInlineClass.kt")
public void testEqualsImplForInlineClassWrappingNullableInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");
@@ -26154,6 +26154,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/defaultArguments.kt");
}
@TestMetadata("equalsImplForInlineClassWrappingNullableInlineClass.kt")
public void testEqualsImplForInlineClassWrappingNullableInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");
@@ -26154,6 +26154,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/defaultArguments.kt");
}
@TestMetadata("equalsImplForInlineClassWrappingNullableInlineClass.kt")
public void testEqualsImplForInlineClassWrappingNullableInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");
@@ -26154,6 +26154,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/defaultArguments.kt");
}
@TestMetadata("equalsImplForInlineClassWrappingNullableInlineClass.kt")
public void testEqualsImplForInlineClassWrappingNullableInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");
@@ -14352,6 +14352,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/unsignedTypes/checkBasicUnsignedLiterals.kt");
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/defaultArguments.kt");
}
@TestMetadata("equalsImplForInlineClassWrappingNullableInlineClass.kt")
public void testEqualsImplForInlineClassWrappingNullableInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/unsignedTypes/equalsImplForInlineClassWrappingNullableInlineClass.kt");