From b033b9180bd5f70e38297feca7bcd582ff45fce7 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 26 Mar 2019 14:09:56 +0300 Subject: [PATCH] [NI] Avoid builder-inference algorithm if types specified explicitly #KT-30620 Fixed --- .../calls/components/ResolutionParts.kt | 3 ++ .../chainCallWithExtensionExplicitTypes.kt | 24 +++++++++++++ .../chainCallWithExtensionExplicitTypes.txt | 35 +++++++++++++++++++ .../DiagnosticsTestWithStdLibGenerated.java | 5 +++ ...ticsTestWithStdLibUsingJavacGenerated.java | 5 +++ 5 files changed, 72 insertions(+) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.txt diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index cb444dcd426..9d91c7806fc 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -236,6 +236,9 @@ internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() { val receiverType = parameter.type.getReceiverTypeFromFunctionType() ?: continue for (freshVariable in resolvedCall.substitutor.freshVariables) { + if (resolvedCall.typeArgumentMappingByOriginal.getTypeArgument(freshVariable.originalTypeParameter) is SimpleTypeArgument) + continue + if (csBuilder.isPostponedTypeVariable(freshVariable)) continue if (receiverType.contains { it.constructor == freshVariable.originalTypeParameter.typeConstructor }) { csBuilder.markPostponedVariable(freshVariable) diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt new file mode 100644 index 00000000000..61830449b3b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !USE_EXPERIMENTAL: kotlin.Experimental + +import kotlin.experimental.ExperimentalTypeInference + +class Inv(val value: K) + +interface ProducerScope { + val prop: Inv +} +class CoroutineScope +class ReceiveChannel + +@UseExperimental(ExperimentalTypeInference::class) +public fun produce(@BuilderInference block: suspend ProducerScope.() -> Unit): ProducerScope = TODO() + +fun test(ls: List) = + produce { + ls.asReceiveChannel().toChannel(prop) + } + +private fun Iterable.asReceiveChannel(): ReceiveChannel = TODO() +public suspend fun ReceiveChannel.toChannel(destination: C): C = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.txt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.txt new file mode 100644 index 00000000000..70a82dbcf0e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.txt @@ -0,0 +1,35 @@ +package + +@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun produce(/*0*/ @kotlin.BuilderInference block: suspend ProducerScope.() -> kotlin.Unit): ProducerScope +public fun test(/*0*/ ls: kotlin.collections.List): ProducerScope +private fun kotlin.collections.Iterable.asReceiveChannel(): ReceiveChannel +public suspend fun ReceiveChannel.toChannel(/*0*/ destination: C): C + +public final class CoroutineScope { + public constructor CoroutineScope() + 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 +} + +public final class Inv { + public constructor Inv(/*0*/ value: K) + public final val value: K + 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 +} + +public interface ProducerScope { + public abstract val prop: Inv + 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 +} + +public final class ReceiveChannel { + public constructor ReceiveChannel() + 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/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index aea2c5c3236..4fb85989384 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -1802,6 +1802,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.kt"); } + @TestMetadata("chainCallWithExtensionExplicitTypes.kt") + public void testChainCallWithExtensionExplicitTypes() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt"); + } + @TestMetadata("correctMember.kt") public void testCorrectMember() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index 90f48225fb8..7123b09c73d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -1802,6 +1802,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/applyInsideCoroutine.kt"); } + @TestMetadata("chainCallWithExtensionExplicitTypes.kt") + public void testChainCallWithExtensionExplicitTypes() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/chainCallWithExtensionExplicitTypes.kt"); + } + @TestMetadata("correctMember.kt") public void testCorrectMember() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/correctMember.kt");