From 832f468b1372856611f6345aa3e7f53bdc549178 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Fri, 1 Apr 2016 20:55:59 +0300 Subject: [PATCH] KT-11733 Cannot infer type parameter in SAM with nullability annotations #KT-11733 Fixed --- .../kotlin/resolve/calls/CallResolverUtil.kt | 3 ++- .../tests/functionLiterals/kt11733.kt | 15 +++++++++++++++ .../tests/functionLiterals/kt11733.txt | 11 +++++++++++ .../tests/functionLiterals/kt11733_1.kt | 16 ++++++++++++++++ .../tests/functionLiterals/kt11733_1.txt | 12 ++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 12 ++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt11733.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt11733.txt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.kt create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt index 18be2c4ec8e..22161a60563 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolverUtil.kt @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.validation.InfixValidator import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +import org.jetbrains.kotlin.types.typeUtil.contains import org.jetbrains.kotlin.util.OperatorNameConventions enum class ResolveArgumentsMode { @@ -47,7 +48,7 @@ enum class ResolveArgumentsMode { fun hasUnknownFunctionParameter(type: KotlinType): Boolean { assert(ReflectionTypes.isCallableType(type)) { "type $type is not a function or property" } return getParameterArgumentsOfCallableType(type).any { - TypeUtils.contains(it.type, DONT_CARE) || ErrorUtils.containsUninferredParameter(it.type) + it.type.contains { TypeUtils.isDontCarePlaceholder(it) } || ErrorUtils.containsUninferredParameter(it.type) } } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt11733.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt11733.kt new file mode 100644 index 00000000000..53a4742dbe5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt11733.kt @@ -0,0 +1,15 @@ +// !CHECK_TYPE + +interface Predicate + +fun Predicate(x: (T?) -> Boolean): Predicate = null!! + +fun foo() { + process(Predicate { + x -> x checkType { _() } + + true + }) +} + +fun process(x: Predicate) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt11733.txt b/compiler/testData/diagnostics/tests/functionLiterals/kt11733.txt new file mode 100644 index 00000000000..b2e3ce23247 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt11733.txt @@ -0,0 +1,11 @@ +package + +public fun Predicate(/*0*/ x: (T?) -> kotlin.Boolean): Predicate +public fun foo(): kotlin.Unit +public fun process(/*0*/ x: Predicate): kotlin.Unit + +public interface Predicate { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.kt b/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.kt new file mode 100644 index 00000000000..ca980a931d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.kt @@ -0,0 +1,16 @@ +// !CHECK_TYPE + +// FILE: Predicate.java +import org.jetbrains.annotations.NotNull + +public interface Predicate { + // Same effect with @Nullable here + boolean invoke(@NotNull T t); +} +// FILE: Main.kt +fun process(x: Predicate) {} +fun main(args: Array) { + process(Predicate { x -> x checkType { _() } + true + }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.txt b/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.txt new file mode 100644 index 00000000000..9f6df691b6a --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.txt @@ -0,0 +1,12 @@ +package + +public /*synthesized*/ fun Predicate(/*0*/ function: (T) -> kotlin.Boolean): Predicate +public fun main(/*0*/ args: kotlin.Array): kotlin.Unit +public fun process(/*0*/ x: Predicate): kotlin.Unit + +public interface Predicate { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract operator fun invoke(/*0*/ @org.jetbrains.annotations.NotNull() t: T): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 0572fa5dfe3..8e3262cc6e4 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -6735,6 +6735,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt11733.kt") + public void testKt11733() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt11733.kt"); + doTest(fileName); + } + + @TestMetadata("kt11733_1.kt") + public void testKt11733_1() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt11733_1.kt"); + doTest(fileName); + } + @TestMetadata("kt2906.kt") public void testKt2906() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt");