From f2aacf774e242edac60bc6d7bfebba59fe873e35 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 17 Feb 2017 18:11:47 +0300 Subject: [PATCH] Get rid of redundant not-null assertion for parameter The problem was that in `Function.apply(T)` T is now not-platform, so when checking if not-null assertion is needed for parameter in SAM, it's defined by the upper bounds of T that is a platform (Any..Any?), and while it's definitely not marked as nullable it's still nullable in a sense that it can contain null as a value. So the solution is obvious #KT-16413 Fixed --- .../codegen/java8/box/functionAssertion.kt | 21 +++++++++++++++++++ ...BlackBoxWithJava8CodegenTestGenerated.java | 6 ++++++ .../org/jetbrains/kotlin/types/TypeUtils.java | 3 +-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/java8/box/functionAssertion.kt diff --git a/compiler/testData/codegen/java8/box/functionAssertion.kt b/compiler/testData/codegen/java8/box/functionAssertion.kt new file mode 100644 index 00000000000..e5a64f7cb38 --- /dev/null +++ b/compiler/testData/codegen/java8/box/functionAssertion.kt @@ -0,0 +1,21 @@ +// FILE: F.java +import java.util.function.Function; + +public class F { + public static U passNull(Function f) { + return f.apply(null); + } +} + +// FILE: test.kt +// WITH_RUNTIME +// FULL_JDK +fun test(f: (Int?) -> String): String { + return F.passNull(f) +} + +fun box(): String { + return test { + it?.toString() ?: "OK" + } +} diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java index ceffeb2cfa8..ddc46367605 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java @@ -84,6 +84,12 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg doTest(fileName); } + @TestMetadata("functionAssertion.kt") + public void testFunctionAssertion() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/functionAssertion.kt"); + doTest(fileName); + } + @TestMetadata("inheritKotlin.kt") public void testInheritKotlin() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/inheritKotlin.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java index ad7b4eccb18..6c0ceabe2fb 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.java @@ -304,8 +304,7 @@ public class TypeUtils { } for (KotlinType supertype : getImmediateSupertypes(type)) { - if (supertype.isMarkedNullable()) return true; - if (hasNullableSuperType(supertype)) return true; + if (isNullableType(supertype)) return true; } return false;