From 96a3831febb2f0a66041e48781758011f29b954b Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 15 May 2019 11:45:43 +0300 Subject: [PATCH] [NI] Add capturing receiver type for callable references #KT-30292 Fixed --- .../resolve/calls/components/CallableReferenceResolution.kt | 4 +++- .../diagnostics/testsWithStdLib/inference/kt30292.kt | 5 +++++ .../diagnostics/testsWithStdLib/inference/kt30292.txt | 3 +++ .../kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java | 5 +++++ .../javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java | 5 +++++ 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.txt diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index a8154a60acc..a25085cb4d7 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.checker.captureFromExpression import org.jetbrains.kotlin.types.expressions.CoercionStrategy import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes import org.jetbrains.kotlin.types.typeUtil.isUnit @@ -142,7 +143,8 @@ private fun ConstraintSystemOperation.addReceiverConstraint( } val expectedType = toFreshSubstitutor.safeSubstitute(receiverParameter.value.type.unwrap()) - val receiverType = receiverArgument.receiver.stableType + val receiverType = receiverArgument.receiver.stableType.let { captureFromExpression(it) ?: it } + addSubtypeConstraint(receiverType, expectedType, position) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.kt new file mode 100644 index 00000000000..1c164720a43 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.kt @@ -0,0 +1,5 @@ +// !LANGUAGE: +NewInference + +fun test(ls: List) { + ls.takeIf(Collection<*>::isNotEmpty) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.txt new file mode 100644 index 00000000000..0a2de764edd --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.txt @@ -0,0 +1,3 @@ +package + +public fun test(/*0*/ ls: kotlin.collections.List): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 8c2e7b8364c..dfaf73f8dbe 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -2696,6 +2696,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt1558.kt"); } + @TestMetadata("kt30292.kt") + public void testKt30292() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.kt"); + } + @TestMetadata("kt3458.kt") public void testKt3458() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index 556f1b8ce29..5a698f2f4aa 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -2696,6 +2696,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt1558.kt"); } + @TestMetadata("kt30292.kt") + public void testKt30292() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt30292.kt"); + } + @TestMetadata("kt3458.kt") public void testKt3458() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/kt3458.kt");