JVM_IR indy: fix non-null assertions on indy lambda parameters
KT-44278 KT-26060 KT-42621
This commit is contained in:
+6
@@ -19939,6 +19939,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/genericFunInterfaceWithPrimitive.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullabilityAssertions.kt")
|
||||
public void testNullabilityAssertions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/nullabilityAssertions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("possibleOverrideClash.kt")
|
||||
public void testPossibleOverrideClash() throws Exception {
|
||||
|
||||
+8
-1
@@ -275,7 +275,7 @@ class ExpressionCodegen(
|
||||
return
|
||||
|
||||
if (inlinedInto != null ||
|
||||
(DescriptorVisibilities.isPrivate(irFunction.visibility) && !(irFunction is IrSimpleFunction && irFunction.isOperator)) ||
|
||||
(DescriptorVisibilities.isPrivate(irFunction.visibility) && !shouldGenerateNonNullAssertionsForPrivateFun(irFunction)) ||
|
||||
irFunction.origin.isSynthetic ||
|
||||
// TODO: refine this condition to not generate nullability assertions on parameters
|
||||
// corresponding to captured variables and anonymous object super constructor arguments
|
||||
@@ -310,6 +310,13 @@ class ExpressionCodegen(
|
||||
}
|
||||
}
|
||||
|
||||
// * Operator functions require non-null assertions on parameters even if they are private.
|
||||
// * Local function for lambda survives at this stage if it was used in 'invokedynamic'-based code.
|
||||
// Such functions require non-null assertions on parameters.
|
||||
private fun shouldGenerateNonNullAssertionsForPrivateFun(irFunction: IrFunction) =
|
||||
irFunction is IrSimpleFunction && irFunction.isOperator ||
|
||||
irFunction.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
|
||||
|
||||
private fun generateNonNullAssertion(param: IrValueParameter) {
|
||||
val asmType = param.type.asmType
|
||||
if (!param.type.unboxInlineClass().isNullable() && !isPrimitive(asmType)) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// FILE: nullabilityAssertions.kt
|
||||
fun box(): String {
|
||||
fun justSomeLocalFun() {}
|
||||
|
||||
try {
|
||||
A.bar {}
|
||||
} catch (e: NullPointerException) {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
return "Should throw NullPointerException"
|
||||
}
|
||||
|
||||
// FILE: A.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface A {
|
||||
void foo(@NotNull String s);
|
||||
|
||||
static void bar(A a) {
|
||||
a.foo(null);
|
||||
}
|
||||
}
|
||||
+6
@@ -19939,6 +19939,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/genericFunInterfaceWithPrimitive.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullabilityAssertions.kt")
|
||||
public void testNullabilityAssertions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/nullabilityAssertions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("possibleOverrideClash.kt")
|
||||
public void testPossibleOverrideClash() throws Exception {
|
||||
|
||||
+6
@@ -19939,6 +19939,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/genericFunInterfaceWithPrimitive.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullabilityAssertions.kt")
|
||||
public void testNullabilityAssertions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/nullabilityAssertions.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("possibleOverrideClash.kt")
|
||||
public void testPossibleOverrideClash() throws Exception {
|
||||
|
||||
+5
@@ -16718,6 +16718,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/genericFunInterfaceWithPrimitive.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullabilityAssertions.kt")
|
||||
public void testNullabilityAssertions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/nullabilityAssertions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("possibleOverrideClash.kt")
|
||||
public void testPossibleOverrideClash() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/possibleOverrideClash.kt");
|
||||
|
||||
Reference in New Issue
Block a user