From b7849da19e7776eca9db3c1fc87ec7f48a9f0cec Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Fri, 7 Jun 2019 15:51:45 +0300 Subject: [PATCH] [NI] Introduce flag to change constraint system for overload resolution This commit doesn't change behaviour of any inference algorithm, it introduces opportunity to switch constraint system that is used for overload resolution and fix problematic cases by changing one enum entry. Due to fundamental changes, there are cases where a new inference algorithm reports overload resolution ambiguity errors (#KT-31670, #KT-31758), which is correct from its point of view. However, this is a breaking change and to really make it, we should be very confident and have enough motivation for it, therefore, we don't change behavior now in order to collect more examples (if there are any). And if we find a lot of erroneous examples, we'll be able to change the behavior quite simply --- .../fir/FirDiagnosticsSmokeTestGenerated.java | 30 +++++++++++++++++++ .../jetbrains/kotlin/config/AnalysisFlags.kt | 3 ++ .../KotlinResolutionStatelessCallbacksImpl.kt | 7 ++++- .../resolve/overloadConflicts/kt31670.kt | 16 ++++++++++ .../resolve/overloadConflicts/kt31670.txt | 21 +++++++++++++ .../overloadConflicts/kt31670_compat.kt | 16 ++++++++++ .../overloadConflicts/kt31670_compat.txt | 21 +++++++++++++ .../resolve/overloadConflicts/kt31758.kt | 26 ++++++++++++++++ .../resolve/overloadConflicts/kt31758.txt | 30 +++++++++++++++++++ .../overloadConflicts/kt31758_compat.kt | 26 ++++++++++++++++ .../overloadConflicts/kt31758_compat.txt | 30 +++++++++++++++++++ ...olutionOnNullableContravariantParameter.kt | 24 +++++++++++++++ ...lutionOnNullableContravariantParameter.txt | 11 +++++++ ...OnNullableContravariantParameter_compat.kt | 24 +++++++++++++++ ...nNullableContravariantParameter_compat.txt | 11 +++++++ .../CompilerTestLanguageVersionSettings.kt | 6 +++- .../checkers/DiagnosticsTestGenerated.java | 30 +++++++++++++++++++ .../DiagnosticsUsingJavacTestGenerated.java | 30 +++++++++++++++++++ .../jetbrains/kotlin/config/AnalysisFlag.kt | 5 ++++ ...nstraintSystemForOverloadResolutionMode.kt | 12 ++++++++ 20 files changed, 377 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.txt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.txt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.txt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.txt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.txt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.txt create mode 100644 compiler/util/src/org/jetbrains/kotlin/config/ConstraintSystemForOverloadResolutionMode.kt diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index 45baa9c7b9b..eb282623294 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -17900,6 +17900,26 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10640.kt"); } + @TestMetadata("kt31670.kt") + public void testKt31670() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.kt"); + } + + @TestMetadata("kt31670_compat.kt") + public void testKt31670_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.kt"); + } + + @TestMetadata("kt31758.kt") + public void testKt31758() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.kt"); + } + + @TestMetadata("kt31758_compat.kt") + public void testKt31758_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.kt"); + } + @TestMetadata("numberOfDefaults.kt") public void testNumberOfDefaults() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/numberOfDefaults.kt"); @@ -17910,6 +17930,16 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/originalExamples.kt"); } + @TestMetadata("overloadResolutionOnNullableContravariantParameter.kt") + public void testOverloadResolutionOnNullableContravariantParameter() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.kt"); + } + + @TestMetadata("overloadResolutionOnNullableContravariantParameter_compat.kt") + public void testOverloadResolutionOnNullableContravariantParameter_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.kt"); + } + @TestMetadata("varargWithMoreSpecificSignature.kt") public void testVarargWithMoreSpecificSignature() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargWithMoreSpecificSignature.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/config/AnalysisFlags.kt b/compiler/frontend/src/org/jetbrains/kotlin/config/AnalysisFlags.kt index 2709a78815b..cf45b13de61 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/config/AnalysisFlags.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/config/AnalysisFlags.kt @@ -29,4 +29,7 @@ object AnalysisFlags { @JvmStatic val allowResultReturnType by AnalysisFlag.Delegates.Boolean + + @JvmStatic + val constraintSystemForOverloadResolution by AnalysisFlag.Delegates.ConstraintSystemForOverloadResolution } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt index 62ad6590aed..5034bc1257a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.resolve.calls.tower import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.config.AnalysisFlags import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor @@ -28,6 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInfixCall import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isSuperOrDelegatingConstructorCall import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionStatelessCallbacks +import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector import org.jetbrains.kotlin.resolve.calls.inference.components.SimpleConstraintSystemImpl import org.jetbrains.kotlin.resolve.calls.inference.isCoroutineCallWithAdditionalInference @@ -88,6 +90,9 @@ class KotlinResolutionStatelessCallbacksImpl( override fun createConstraintSystemForOverloadResolution( constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns ): SimpleConstraintSystem { - return SimpleConstraintSystemImpl(constraintInjector, builtIns) + return if (languageVersionSettings.getFlag(AnalysisFlags.constraintSystemForOverloadResolution).forNewInference()) + SimpleConstraintSystemImpl(constraintInjector, builtIns) + else + ConstraintSystemBuilderImpl.forSpecificity() } } diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.kt new file mode 100644 index 00000000000..2ac53c3ca76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE + +open class A(val value: T) +class B(value: T) : A(value) + +fun A.foo(block: (T?) -> Unit) { + block(value) +} +fun B.foo(block: (T) -> Unit) { + block(value) +} + +fun main() { + B("string").foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.txt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.txt new file mode 100644 index 00000000000..81a675d81c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.txt @@ -0,0 +1,21 @@ +package + +public fun main(): kotlin.Unit +public fun A.foo(/*0*/ block: (T?) -> kotlin.Unit): kotlin.Unit +public fun B.foo(/*0*/ block: (T) -> kotlin.Unit): kotlin.Unit + +public open class A { + public constructor A(/*0*/ value: T) + public final val value: T + 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 B : A { + public constructor B(/*0*/ value: T) + public final override /*1*/ /*fake_override*/ val value: T + 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/resolve/overloadConflicts/kt31670_compat.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.kt new file mode 100644 index 00000000000..187c04c7a18 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.kt @@ -0,0 +1,16 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_OLD_INFERENCE + +open class A(val value: T) +class B(value: T) : A(value) + +fun A.foo(block: (T?) -> Unit) { + block(value) +} +fun B.foo(block: (T) -> Unit) { + block(value) +} + +fun main() { + B("string").foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.txt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.txt new file mode 100644 index 00000000000..81a675d81c0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.txt @@ -0,0 +1,21 @@ +package + +public fun main(): kotlin.Unit +public fun A.foo(/*0*/ block: (T?) -> kotlin.Unit): kotlin.Unit +public fun B.foo(/*0*/ block: (T) -> kotlin.Unit): kotlin.Unit + +public open class A { + public constructor A(/*0*/ value: T) + public final val value: T + 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 B : A { + public constructor B(/*0*/ value: T) + public final override /*1*/ /*fake_override*/ val value: T + 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/resolve/overloadConflicts/kt31758.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.kt new file mode 100644 index 00000000000..f36b2217a25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package a + +enum class A { A1 } + +fun > foo(arg: T.() -> Unit) = 1 + +// FILE: b.kt + +package b + +fun foo(arg: T.() -> Unit) = 2 + +// FILE: test.kt + +import a.* +import b.* + +fun test() { + foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.txt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.txt new file mode 100644 index 00000000000..3fff25c24cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.txt @@ -0,0 +1,30 @@ +package + +public fun test(): kotlin.Unit + +package a { + public fun > foo(/*0*/ arg: T.() -> kotlin.Unit): kotlin.Int + + public final enum class A : kotlin.Enum { + enum entry A1 + + private constructor A() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: a.A): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): a.A + public final /*synthesized*/ fun values(): kotlin.Array + } +} + +package b { + public fun foo(/*0*/ arg: T.() -> kotlin.Unit): kotlin.Int +} diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.kt new file mode 100644 index 00000000000..d3726df733a --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.kt @@ -0,0 +1,26 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_OLD_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package a + +enum class A { A1 } + +fun > foo(arg: T.() -> Unit) = 1 + +// FILE: b.kt + +package b + +fun foo(arg: T.() -> Unit) = 2 + +// FILE: test.kt + +import a.* +import b.* + +fun test() { + foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.txt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.txt new file mode 100644 index 00000000000..3fff25c24cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.txt @@ -0,0 +1,30 @@ +package + +public fun test(): kotlin.Unit + +package a { + public fun > foo(/*0*/ arg: T.() -> kotlin.Unit): kotlin.Int + + public final enum class A : kotlin.Enum { + enum entry A1 + + private constructor A() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: a.A): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): a.A + public final /*synthesized*/ fun values(): kotlin.Array + } +} + +package b { + public fun foo(/*0*/ arg: T.() -> kotlin.Unit): kotlin.Int +} diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.kt new file mode 100644 index 00000000000..6b3d3afc83f --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package a + +fun foo(block: (T?) -> Unit) {} + +// FILE: b.kt + +package b + +fun foo(block: (K) -> Unit) {} + +// FILE: test.kt + +import a.* +import b.* + +fun main() { + foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.txt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.txt new file mode 100644 index 00000000000..607442c7911 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.txt @@ -0,0 +1,11 @@ +package + +public fun main(): kotlin.Unit + +package a { + public fun foo(/*0*/ block: (T?) -> kotlin.Unit): kotlin.Unit +} + +package b { + public fun foo(/*0*/ block: (K) -> kotlin.Unit): kotlin.Unit +} diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.kt new file mode 100644 index 00000000000..fbf05b27471 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.kt @@ -0,0 +1,24 @@ +// !WITH_NEW_INFERENCE +// !CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION: CONSTRAINT_SYSTEM_FOR_OLD_INFERENCE +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// FILE: a.kt + +package a + +fun foo(block: (T?) -> Unit) {} + +// FILE: b.kt + +package b + +fun foo(block: (K) -> Unit) {} + +// FILE: test.kt + +import a.* +import b.* + +fun main() { + foo { } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.txt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.txt new file mode 100644 index 00000000000..607442c7911 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.txt @@ -0,0 +1,11 @@ +package + +public fun main(): kotlin.Unit + +package a { + public fun foo(/*0*/ block: (T?) -> kotlin.Unit): kotlin.Unit +} + +package b { + public fun foo(/*0*/ block: (K) -> kotlin.Unit): kotlin.Unit +} diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/CompilerTestLanguageVersionSettings.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/CompilerTestLanguageVersionSettings.kt index e89ba2e20ca..01386e08a79 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/CompilerTestLanguageVersionSettings.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/CompilerTestLanguageVersionSettings.kt @@ -23,6 +23,7 @@ const val SKIP_METADATA_VERSION_CHECK = "SKIP_METADATA_VERSION_CHECK" const val ALLOW_RESULT_RETURN_TYPE = "ALLOW_RESULT_RETURN_TYPE" const val INHERIT_MULTIFILE_PARTS = "INHERIT_MULTIFILE_PARTS" const val SANITIZE_PARENTHESES = "SANITIZE_PARENTHESES" +const val CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION = "CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION" data class CompilerTestLanguageVersionSettings( private val initialLanguageFeatures: Map, @@ -64,7 +65,10 @@ fun parseLanguageVersionSettings(directives: Map): CompilerTestL analysisFlag(AnalysisFlags.skipMetadataVersionCheck, if (SKIP_METADATA_VERSION_CHECK in directives) true else null), analysisFlag(AnalysisFlags.allowResultReturnType, if (ALLOW_RESULT_RETURN_TYPE in directives) true else null), analysisFlag(JvmAnalysisFlags.inheritMultifileParts, if (INHERIT_MULTIFILE_PARTS in directives) true else null), - analysisFlag(JvmAnalysisFlags.sanitizeParentheses, if (SANITIZE_PARENTHESES in directives) true else null) + analysisFlag(JvmAnalysisFlags.sanitizeParentheses, if (SANITIZE_PARENTHESES in directives) true else null), + analysisFlag(AnalysisFlags.constraintSystemForOverloadResolution, directives[CONSTRAINT_SYSTEM_FOR_OVERLOAD_RESOLUTION]?.let { + ConstraintSystemForOverloadResolutionMode.valueOf(it) + }) ) if (apiVersionString == null && languageFeaturesString == null && analysisFlags.isEmpty()) { diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 22b88e98256..1c88b376c97 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -17912,6 +17912,26 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10640.kt"); } + @TestMetadata("kt31670.kt") + public void testKt31670() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.kt"); + } + + @TestMetadata("kt31670_compat.kt") + public void testKt31670_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.kt"); + } + + @TestMetadata("kt31758.kt") + public void testKt31758() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.kt"); + } + + @TestMetadata("kt31758_compat.kt") + public void testKt31758_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.kt"); + } + @TestMetadata("numberOfDefaults.kt") public void testNumberOfDefaults() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/numberOfDefaults.kt"); @@ -17922,6 +17942,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/originalExamples.kt"); } + @TestMetadata("overloadResolutionOnNullableContravariantParameter.kt") + public void testOverloadResolutionOnNullableContravariantParameter() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.kt"); + } + + @TestMetadata("overloadResolutionOnNullableContravariantParameter_compat.kt") + public void testOverloadResolutionOnNullableContravariantParameter_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.kt"); + } + @TestMetadata("varargWithMoreSpecificSignature.kt") public void testVarargWithMoreSpecificSignature() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargWithMoreSpecificSignature.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 13616606c39..3d4781f19d6 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -17902,6 +17902,26 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt10640.kt"); } + @TestMetadata("kt31670.kt") + public void testKt31670() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670.kt"); + } + + @TestMetadata("kt31670_compat.kt") + public void testKt31670_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31670_compat.kt"); + } + + @TestMetadata("kt31758.kt") + public void testKt31758() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758.kt"); + } + + @TestMetadata("kt31758_compat.kt") + public void testKt31758_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt31758_compat.kt"); + } + @TestMetadata("numberOfDefaults.kt") public void testNumberOfDefaults() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/numberOfDefaults.kt"); @@ -17912,6 +17932,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/originalExamples.kt"); } + @TestMetadata("overloadResolutionOnNullableContravariantParameter.kt") + public void testOverloadResolutionOnNullableContravariantParameter() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter.kt"); + } + + @TestMetadata("overloadResolutionOnNullableContravariantParameter_compat.kt") + public void testOverloadResolutionOnNullableContravariantParameter_compat() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/overloadResolutionOnNullableContravariantParameter_compat.kt"); + } + @TestMetadata("varargWithMoreSpecificSignature.kt") public void testVarargWithMoreSpecificSignature() throws Exception { runTest("compiler/testData/diagnostics/tests/resolve/overloadConflicts/varargWithMoreSpecificSignature.kt"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/AnalysisFlag.kt b/compiler/util/src/org/jetbrains/kotlin/config/AnalysisFlag.kt index 9c4b2f8b91b..e886794305e 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/AnalysisFlag.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/AnalysisFlag.kt @@ -41,5 +41,10 @@ class AnalysisFlag internal constructor( object ListOfStrings { operator fun provideDelegate(instance: Any?, property: KProperty<*>) = Delegate(property.name, emptyList()) } + + object ConstraintSystemForOverloadResolution { + operator fun provideDelegate(instance: Any?, property: KProperty<*>) = + Delegate(property.name, ConstraintSystemForOverloadResolutionMode.CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE) + } } } diff --git a/compiler/util/src/org/jetbrains/kotlin/config/ConstraintSystemForOverloadResolutionMode.kt b/compiler/util/src/org/jetbrains/kotlin/config/ConstraintSystemForOverloadResolutionMode.kt new file mode 100644 index 00000000000..9cf2ec1c9a0 --- /dev/null +++ b/compiler/util/src/org/jetbrains/kotlin/config/ConstraintSystemForOverloadResolutionMode.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.config + +enum class ConstraintSystemForOverloadResolutionMode { + CONSTRAINT_SYSTEM_FOR_OLD_INFERENCE, CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE; + + fun forNewInference(): Boolean = this == CONSTRAINT_SYSTEM_FOR_NEW_INFERENCE +} \ No newline at end of file