Fix codegen of !! for nullable generics
This commit is contained in:
@@ -2669,21 +2669,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
@Override
|
@Override
|
||||||
public StackValue visitPostfixExpression(JetPostfixExpression expression, StackValue receiver) {
|
public StackValue visitPostfixExpression(JetPostfixExpression expression, StackValue receiver) {
|
||||||
if (expression.getOperationReference().getReferencedNameElementType() == JetTokens.EXCLEXCL) {
|
if (expression.getOperationReference().getReferencedNameElementType() == JetTokens.EXCLEXCL) {
|
||||||
JetExpression baseExpression = expression.getBaseExpression();
|
StackValue base = genQualified(receiver, expression.getBaseExpression());
|
||||||
JetType type = bindingContext.get(BindingContext.EXPRESSION_TYPE, baseExpression);
|
if (isPrimitive(base.type)) {
|
||||||
StackValue base = genQualified(receiver, baseExpression);
|
|
||||||
if (type != null && type.isNullable()) {
|
|
||||||
base.put(base.type, v);
|
|
||||||
v.dup();
|
|
||||||
Label ok = new Label();
|
|
||||||
v.ifnonnull(ok);
|
|
||||||
v.invokestatic("jet/runtime/Intrinsics", "throwNpe", "()V");
|
|
||||||
v.mark(ok);
|
|
||||||
return StackValue.onStack(base.type);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
base.put(base.type, v);
|
||||||
|
v.dup();
|
||||||
|
Label ok = new Label();
|
||||||
|
v.ifnonnull(ok);
|
||||||
|
v.invokestatic("jet/runtime/Intrinsics", "throwNpe", "()V");
|
||||||
|
v.mark(ok);
|
||||||
|
return StackValue.onStack(base.type);
|
||||||
}
|
}
|
||||||
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
|
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
|
||||||
if (op instanceof FunctionDescriptor) {
|
if (op instanceof FunctionDescriptor) {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fun foo<T>(t: T) {
|
||||||
|
t!!
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
try {
|
||||||
|
foo<Any?>(null)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
return "Fail"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun box(): String {
|
||||||
|
42!!
|
||||||
|
42.toLong()!!
|
||||||
|
return "OK"!!
|
||||||
|
}
|
||||||
+20
-1
@@ -30,7 +30,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
|
|||||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@TestMetadata("compiler/testData/codegen/box")
|
@TestMetadata("compiler/testData/codegen/box")
|
||||||
@InnerTestClasses({BlackBoxCodegenTestGenerated.Arrays.class, BlackBoxCodegenTestGenerated.Bridges.class, BlackBoxCodegenTestGenerated.Casts.class, BlackBoxCodegenTestGenerated.Classes.class, BlackBoxCodegenTestGenerated.Closures.class, BlackBoxCodegenTestGenerated.ControlStructures.class, BlackBoxCodegenTestGenerated.DefaultArguments.class, BlackBoxCodegenTestGenerated.Elvis.class, BlackBoxCodegenTestGenerated.Enum.class, BlackBoxCodegenTestGenerated.ExtensionFunctions.class, BlackBoxCodegenTestGenerated.ExtensionProperties.class, BlackBoxCodegenTestGenerated.Functions.class, BlackBoxCodegenTestGenerated.InnerNested.class, BlackBoxCodegenTestGenerated.Instructions.class, BlackBoxCodegenTestGenerated.Intrinsics.class, BlackBoxCodegenTestGenerated.Labels.class, BlackBoxCodegenTestGenerated.LocalClasses.class, BlackBoxCodegenTestGenerated.MultiDecl.class, BlackBoxCodegenTestGenerated.Namespace.class, BlackBoxCodegenTestGenerated.Objects.class, BlackBoxCodegenTestGenerated.OperatorConventions.class, BlackBoxCodegenTestGenerated.PrimitiveTypes.class, BlackBoxCodegenTestGenerated.Properties.class, BlackBoxCodegenTestGenerated.SafeCall.class, BlackBoxCodegenTestGenerated.Strings.class, BlackBoxCodegenTestGenerated.Super.class, BlackBoxCodegenTestGenerated.Traits.class, BlackBoxCodegenTestGenerated.TypeInfo.class, BlackBoxCodegenTestGenerated.Unit.class, BlackBoxCodegenTestGenerated.Vararg.class, BlackBoxCodegenTestGenerated.When.class})
|
@InnerTestClasses({BlackBoxCodegenTestGenerated.Arrays.class, BlackBoxCodegenTestGenerated.Bridges.class, BlackBoxCodegenTestGenerated.Casts.class, BlackBoxCodegenTestGenerated.Classes.class, BlackBoxCodegenTestGenerated.Closures.class, BlackBoxCodegenTestGenerated.ControlStructures.class, BlackBoxCodegenTestGenerated.DefaultArguments.class, BlackBoxCodegenTestGenerated.Elvis.class, BlackBoxCodegenTestGenerated.Enum.class, BlackBoxCodegenTestGenerated.ExclExcl.class, BlackBoxCodegenTestGenerated.ExtensionFunctions.class, BlackBoxCodegenTestGenerated.ExtensionProperties.class, BlackBoxCodegenTestGenerated.Functions.class, BlackBoxCodegenTestGenerated.InnerNested.class, BlackBoxCodegenTestGenerated.Instructions.class, BlackBoxCodegenTestGenerated.Intrinsics.class, BlackBoxCodegenTestGenerated.Labels.class, BlackBoxCodegenTestGenerated.LocalClasses.class, BlackBoxCodegenTestGenerated.MultiDecl.class, BlackBoxCodegenTestGenerated.Namespace.class, BlackBoxCodegenTestGenerated.Objects.class, BlackBoxCodegenTestGenerated.OperatorConventions.class, BlackBoxCodegenTestGenerated.PrimitiveTypes.class, BlackBoxCodegenTestGenerated.Properties.class, BlackBoxCodegenTestGenerated.SafeCall.class, BlackBoxCodegenTestGenerated.Strings.class, BlackBoxCodegenTestGenerated.Super.class, BlackBoxCodegenTestGenerated.Traits.class, BlackBoxCodegenTestGenerated.TypeInfo.class, BlackBoxCodegenTestGenerated.Unit.class, BlackBoxCodegenTestGenerated.Vararg.class, BlackBoxCodegenTestGenerated.When.class})
|
||||||
public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||||
public void testAllFilesPresentInBox() throws Exception {
|
public void testAllFilesPresentInBox() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box"), "kt", true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box"), "kt", true);
|
||||||
@@ -1492,6 +1492,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/codegen/box/exclExcl")
|
||||||
|
public static class ExclExcl extends AbstractBlackBoxCodegenTest {
|
||||||
|
public void testAllFilesPresentInExclExcl() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/exclExcl"), "kt", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("genericNull.kt")
|
||||||
|
public void testGenericNull() throws Exception {
|
||||||
|
blackBoxFileByFullPath("compiler/testData/codegen/box/exclExcl/genericNull.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("primitive.kt")
|
||||||
|
public void testPrimitive() throws Exception {
|
||||||
|
blackBoxFileByFullPath("compiler/testData/codegen/box/exclExcl/primitive.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/extensionFunctions")
|
@TestMetadata("compiler/testData/codegen/box/extensionFunctions")
|
||||||
public static class ExtensionFunctions extends AbstractBlackBoxCodegenTest {
|
public static class ExtensionFunctions extends AbstractBlackBoxCodegenTest {
|
||||||
public void testAllFilesPresentInExtensionFunctions() throws Exception {
|
public void testAllFilesPresentInExtensionFunctions() throws Exception {
|
||||||
@@ -3372,6 +3390,7 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
suite.addTest(DefaultArguments.innerSuite());
|
suite.addTest(DefaultArguments.innerSuite());
|
||||||
suite.addTestSuite(Elvis.class);
|
suite.addTestSuite(Elvis.class);
|
||||||
suite.addTestSuite(Enum.class);
|
suite.addTestSuite(Enum.class);
|
||||||
|
suite.addTestSuite(ExclExcl.class);
|
||||||
suite.addTestSuite(ExtensionFunctions.class);
|
suite.addTestSuite(ExtensionFunctions.class);
|
||||||
suite.addTestSuite(ExtensionProperties.class);
|
suite.addTestSuite(ExtensionProperties.class);
|
||||||
suite.addTestSuite(Functions.class);
|
suite.addTestSuite(Functions.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user