Introduce compiler key to disable compatibility resolution mechanism
Enable it if one was using new inferene before 1.4 #KT-40128 Fixed #KT-40112 Fixed #KT-40113 Fixed
This commit is contained in:
+3
@@ -388,6 +388,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
|||||||
put(LanguageFeature.NewInference, LanguageFeature.State.ENABLED)
|
put(LanguageFeature.NewInference, LanguageFeature.State.ENABLED)
|
||||||
put(LanguageFeature.SamConversionPerArgument, LanguageFeature.State.ENABLED)
|
put(LanguageFeature.SamConversionPerArgument, LanguageFeature.State.ENABLED)
|
||||||
put(LanguageFeature.FunctionReferenceWithDefaultValueAsOtherType, LanguageFeature.State.ENABLED)
|
put(LanguageFeature.FunctionReferenceWithDefaultValueAsOtherType, LanguageFeature.State.ENABLED)
|
||||||
|
put(LanguageFeature.DisableCompatibilityModeForNewInference, LanguageFeature.State.ENABLED)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inlineClasses) {
|
if (inlineClasses) {
|
||||||
@@ -467,6 +468,8 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
|||||||
|
|
||||||
if (!functionReferenceWithDefaultValueFeaturePassedExplicitly)
|
if (!functionReferenceWithDefaultValueFeaturePassedExplicitly)
|
||||||
put(LanguageFeature.FunctionReferenceWithDefaultValueAsOtherType, LanguageFeature.State.ENABLED)
|
put(LanguageFeature.FunctionReferenceWithDefaultValueAsOtherType, LanguageFeature.State.ENABLED)
|
||||||
|
|
||||||
|
put(LanguageFeature.DisableCompatibilityModeForNewInference, LanguageFeature.State.ENABLED)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (featuresThatForcePreReleaseBinaries.isNotEmpty()) {
|
if (featuresThatForcePreReleaseBinaries.isNotEmpty()) {
|
||||||
|
|||||||
+5
@@ -1924,6 +1924,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityWhenAllReferencesAreInapplicable.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityWhenAllReferencesAreInapplicable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noCompatibilityResolveWithProressiveModeForNI.kt")
|
||||||
|
public void testNoCompatibilityResolveWithProressiveModeForNI() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/noCompatibilityResolveWithProressiveModeForNI.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noExceptionOnRedCodeWithArrayLikeCall.kt")
|
@TestMetadata("noExceptionOnRedCodeWithArrayLikeCall.kt")
|
||||||
public void testNoExceptionOnRedCodeWithArrayLikeCall() throws Exception {
|
public void testNoExceptionOnRedCodeWithArrayLikeCall() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.kt");
|
||||||
|
|||||||
+1
-1
@@ -213,7 +213,7 @@ class CallableReferencesCandidateFactory(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (needCompatibilityResolveForCallableReference(callableReferenceAdaptation, candidateDescriptor)) {
|
if (needCompatibilityResolveForCallableReference(callableReferenceAdaptation, candidateDescriptor)) {
|
||||||
diagnostics.add(LowerPriorityToPreserveCompatibility)
|
markCandidateForCompatibilityResolve(diagnostics)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callableReferenceAdaptation != null &&
|
if (callableReferenceAdaptation != null &&
|
||||||
|
|||||||
+1
-1
@@ -261,7 +261,7 @@ internal object CompatibilityOfTypeVariableAsIntersectionTypePart : ResolutionPa
|
|||||||
|
|
||||||
// See TypeBoundsImpl.computeValues(). It returns several values for such situation which means an error in OI
|
// See TypeBoundsImpl.computeValues(). It returns several values for such situation which means an error in OI
|
||||||
if (callComponents.statelessCallbacks.isOldIntersectionIsEmpty(constraints.map { it.type }.cast())) {
|
if (callComponents.statelessCallbacks.isOldIntersectionIsEmpty(constraints.map { it.type }.cast())) {
|
||||||
addDiagnostic(LowerPriorityToPreserveCompatibility)
|
markCandidateForCompatibilityResolve()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -91,7 +91,7 @@ object SamTypeConversions : ParameterTypeConversion {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (needCompatibilityResolveForSAM(candidate, expectedParameterType)) {
|
if (needCompatibilityResolveForSAM(candidate, expectedParameterType)) {
|
||||||
candidate.addDiagnostic(LowerPriorityToPreserveCompatibility)
|
candidate.markCandidateForCompatibilityResolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
val samDescriptor = originalExpectedType.constructor.declarationDescriptor
|
val samDescriptor = originalExpectedType.constructor.declarationDescriptor
|
||||||
|
|||||||
+1
-1
@@ -52,7 +52,7 @@ object SuspendTypeConversions : ParameterTypeConversion {
|
|||||||
|
|
||||||
candidate.resolvedCall.registerArgumentWithSuspendConversion(argument, nonSuspendParameterType)
|
candidate.resolvedCall.registerArgumentWithSuspendConversion(argument, nonSuspendParameterType)
|
||||||
|
|
||||||
candidate.addDiagnostic(LowerPriorityToPreserveCompatibility)
|
candidate.markCandidateForCompatibilityResolve()
|
||||||
|
|
||||||
return nonSuspendParameterType
|
return nonSuspendParameterType
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserv
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
|
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
|
import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.model.markCandidateForCompatibilityResolve
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
import org.jetbrains.kotlin.types.isDynamic
|
import org.jetbrains.kotlin.types.isDynamic
|
||||||
@@ -78,7 +79,7 @@ object UnitTypeConversions : ParameterTypeConversion {
|
|||||||
|
|
||||||
candidate.resolvedCall.registerArgumentWithUnitConversion(argument, nonUnitReturnedParameterType)
|
candidate.resolvedCall.registerArgumentWithUnitConversion(argument, nonUnitReturnedParameterType)
|
||||||
|
|
||||||
candidate.addDiagnostic(LowerPriorityToPreserveCompatibility)
|
candidate.markCandidateForCompatibilityResolve()
|
||||||
|
|
||||||
return nonUnitReturnedParameterType
|
return nonUnitReturnedParameterType
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-4
@@ -16,22 +16,22 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.model
|
package org.jetbrains.kotlin.resolve.calls.model
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceResolver
|
import org.jetbrains.kotlin.resolve.calls.components.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.NewConstraintSystemImpl
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant
|
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
|
||||||
|
|
||||||
abstract class ResolutionPart {
|
abstract class ResolutionPart {
|
||||||
@@ -250,3 +250,12 @@ class MutableResolvedCallAtom(
|
|||||||
override fun toString(): String = "$atom, candidate = $candidateDescriptor"
|
override fun toString(): String = "$atom, candidate = $candidateDescriptor"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun KotlinResolutionCandidate.markCandidateForCompatibilityResolve() {
|
||||||
|
if (callComponents.languageVersionSettings.supportsFeature(LanguageFeature.DisableCompatibilityModeForNewInference)) return
|
||||||
|
addDiagnostic(LowerPriorityToPreserveCompatibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CallableReferencesCandidateFactory.markCandidateForCompatibilityResolve(diagnostics: SmartList<KotlinCallDiagnostic>) {
|
||||||
|
if (callComponents.languageVersionSettings.supportsFeature(LanguageFeature.DisableCompatibilityModeForNewInference)) return
|
||||||
|
diagnostics.add(LowerPriorityToPreserveCompatibility)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
$TESTDATA_DIR$/newInferenceImpliesProgressiveModeForNI.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-XXLanguage\:+NewInference
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fun bar(): Int = 0
|
||||||
|
|
||||||
|
object Scope {
|
||||||
|
fun <T> foo(f: () -> T): T = f()
|
||||||
|
|
||||||
|
fun bar(x: Int = 0): String = ""
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val r1 = foo(::bar)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
warning: ATTENTION!
|
||||||
|
This build uses unsafe internal compiler arguments:
|
||||||
|
|
||||||
|
-XXLanguage:+NewInference
|
||||||
|
|
||||||
|
This mode is not recommended for production use,
|
||||||
|
as no stability/compatibility guarantees are given on
|
||||||
|
compiler or generated code. Use it at your own risk!
|
||||||
|
|
||||||
|
compiler/testData/cli/jvm/newInferenceImpliesProgressiveModeForNI.kt:6:13: warning: parameter 'x' is never used
|
||||||
|
fun bar(x: Int = 0): String = ""
|
||||||
|
^
|
||||||
|
compiler/testData/cli/jvm/newInferenceImpliesProgressiveModeForNI.kt:9:13: warning: variable 'r1' is never used
|
||||||
|
val r1 = foo(::bar)
|
||||||
|
^
|
||||||
|
OK
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// !LANGUAGE: +DisableCompatibilityModeForNewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||||
|
|
||||||
|
fun bar(): Int = 0
|
||||||
|
|
||||||
|
object Scope {
|
||||||
|
fun <T> foo(f: () -> T): T = f()
|
||||||
|
|
||||||
|
fun bar(x: Int = 0): String = ""
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val r1 = foo(::bar)
|
||||||
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>r1<!>
|
||||||
|
|
||||||
|
val r2 = foo(Scope::bar)
|
||||||
|
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>r2<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun bar(): kotlin.Int
|
||||||
|
|
||||||
|
public object Scope {
|
||||||
|
private constructor Scope()
|
||||||
|
public final fun bar(/*0*/ x: kotlin.Int = ...): kotlin.String
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public final fun </*0*/ T> foo(/*0*/ f: () -> T): T
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final fun test(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -1931,6 +1931,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityWhenAllReferencesAreInapplicable.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityWhenAllReferencesAreInapplicable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noCompatibilityResolveWithProressiveModeForNI.kt")
|
||||||
|
public void testNoCompatibilityResolveWithProressiveModeForNI() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/noCompatibilityResolveWithProressiveModeForNI.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noExceptionOnRedCodeWithArrayLikeCall.kt")
|
@TestMetadata("noExceptionOnRedCodeWithArrayLikeCall.kt")
|
||||||
public void testNoExceptionOnRedCodeWithArrayLikeCall() throws Exception {
|
public void testNoExceptionOnRedCodeWithArrayLikeCall() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.kt");
|
||||||
|
|||||||
Generated
+5
@@ -1926,6 +1926,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityWhenAllReferencesAreInapplicable.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/noAmbiguityWhenAllReferencesAreInapplicable.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noCompatibilityResolveWithProressiveModeForNI.kt")
|
||||||
|
public void testNoCompatibilityResolveWithProressiveModeForNI() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/noCompatibilityResolveWithProressiveModeForNI.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noExceptionOnRedCodeWithArrayLikeCall.kt")
|
@TestMetadata("noExceptionOnRedCodeWithArrayLikeCall.kt")
|
||||||
public void testNoExceptionOnRedCodeWithArrayLikeCall() throws Exception {
|
public void testNoExceptionOnRedCodeWithArrayLikeCall() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/noExceptionOnRedCodeWithArrayLikeCall.kt");
|
||||||
|
|||||||
@@ -540,6 +540,11 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/jvm/multipleTextRangesInDiagnosticsOrder.args");
|
runTest("compiler/testData/cli/jvm/multipleTextRangesInDiagnosticsOrder.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("newInferenceImpliesProgressiveModeForNI.args")
|
||||||
|
public void testNewInferenceImpliesProgressiveModeForNI() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/newInferenceImpliesProgressiveModeForNI.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("newInferenceImpliesSamConversions.args")
|
@TestMetadata("newInferenceImpliesSamConversions.args")
|
||||||
public void testNewInferenceImpliesSamConversions() throws Exception {
|
public void testNewInferenceImpliesSamConversions() throws Exception {
|
||||||
runTest("compiler/testData/cli/jvm/newInferenceImpliesSamConversions.args");
|
runTest("compiler/testData/cli/jvm/newInferenceImpliesSamConversions.args");
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ enum class LanguageFeature(
|
|||||||
ProhibitVarargAsArrayAfterSamArgument(KOTLIN_1_5, kind = BUG_FIX),
|
ProhibitVarargAsArrayAfterSamArgument(KOTLIN_1_5, kind = BUG_FIX),
|
||||||
CorrectSourceMappingSyntax(KOTLIN_1_5, kind = UNSTABLE_FEATURE),
|
CorrectSourceMappingSyntax(KOTLIN_1_5, kind = UNSTABLE_FEATURE),
|
||||||
ProperArrayConventionSetterWithDefaultCalls(KOTLIN_1_5, kind = OTHER),
|
ProperArrayConventionSetterWithDefaultCalls(KOTLIN_1_5, kind = OTHER),
|
||||||
|
DisableCompatibilityModeForNewInference(KOTLIN_1_5, defaultState = LanguageFeature.State.DISABLED),
|
||||||
|
|
||||||
// Temporarily disabled, see KT-27084/KT-22379
|
// Temporarily disabled, see KT-27084/KT-22379
|
||||||
SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX),
|
SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX),
|
||||||
|
|||||||
Reference in New Issue
Block a user