[FE] Provide overloadability for candidates with different CR
This commit is contained in:
committed by
TeamCityServer
parent
155e7b211b
commit
a091b345a0
+6
@@ -10648,6 +10648,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/overloadPriority.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloading.kt")
|
||||
public void testOverloading() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/overloading.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("plusMatrix.kt")
|
||||
public void testPlusMatrix() throws Exception {
|
||||
|
||||
+6
@@ -10648,6 +10648,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/overloadPriority.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloading.kt")
|
||||
public void testOverloading() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/overloading.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("plusMatrix.kt")
|
||||
public void testPlusMatrix() throws Exception {
|
||||
|
||||
+6
@@ -10648,6 +10648,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/overloadPriority.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloading.kt")
|
||||
public void testOverloading() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/overloading.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("plusMatrix.kt")
|
||||
public void testPlusMatrix() throws Exception {
|
||||
|
||||
+6
@@ -16181,6 +16181,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/overload.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloading.kt")
|
||||
public void testOverloading() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/overloading.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("plusAssign.kt")
|
||||
public void testPlusAssign() throws Exception {
|
||||
|
||||
+7
-4
@@ -66,9 +66,11 @@ private fun <T> SimpleConstraintSystem.isValueParameterTypeNotLessSpecific(
|
||||
): Boolean {
|
||||
val typeParameters = general.typeParameters
|
||||
val typeSubstitutor = registerTypeVariables(typeParameters)
|
||||
val valueParameterTypes = specific.valueParameterTypes.map(typeKindSelector).zip(general.valueParameterTypes.map(typeKindSelector))
|
||||
val valueParamsWithoutContextReceivers =
|
||||
specific.valueParameterTypes.drop(specific.contextReceiverCount).map(typeKindSelector)
|
||||
.zip(general.valueParameterTypes.drop(general.contextReceiverCount).map(typeKindSelector))
|
||||
|
||||
for ((specificType, generalType) in valueParameterTypes) {
|
||||
for ((specificType, generalType) in valueParamsWithoutContextReceivers) {
|
||||
if (specificType == null || generalType == null) continue
|
||||
|
||||
if (specificityComparator.isDefinitelyLessSpecific(specificType, generalType)) {
|
||||
@@ -108,8 +110,9 @@ fun <T> SimpleConstraintSystem.isSignatureNotLessSpecific(
|
||||
useOriginalSamTypes: Boolean = false
|
||||
): Boolean {
|
||||
if (specific.hasExtensionReceiver != general.hasExtensionReceiver) return false
|
||||
if (specific.contextReceiverCount != general.contextReceiverCount) return false
|
||||
if (specific.valueParameterTypes.size != general.valueParameterTypes.size) return false
|
||||
if (specific.contextReceiverCount > general.contextReceiverCount) return false
|
||||
if (specific.valueParameterTypes.size - specific.contextReceiverCount != general.valueParameterTypes.size - general.contextReceiverCount)
|
||||
return false
|
||||
|
||||
if (!isValueParameterTypeNotLessSpecific(specific, general, callbacks, specificityComparator) { it?.resultType }) {
|
||||
return false
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.resolve.calls.model
|
||||
import org.jetbrains.kotlin.resolve.calls.components.ArgumentsToCandidateParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CheckArgumentsInParenthesis
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CheckCallableReference
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CheckContextReceiversResolutionPart
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CheckExplicitReceiverKindConsistency
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CheckExternalArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CheckInfixResolutionPart
|
||||
@@ -36,7 +37,8 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
|
||||
CollectionTypeVariableUsagesInfo,
|
||||
CheckExplicitReceiverKindConsistency,
|
||||
CheckReceivers,
|
||||
PostponedVariablesInitializerResolutionPart
|
||||
PostponedVariablesInitializerResolutionPart,
|
||||
CheckContextReceiversResolutionPart
|
||||
),
|
||||
FUNCTION(
|
||||
CheckVisibility,
|
||||
@@ -55,7 +57,8 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
|
||||
EagerResolveOfCallableReferences,
|
||||
CompatibilityOfTypeVariableAsIntersectionTypePart,
|
||||
CompatibilityOfPartiallyApplicableSamConversion,
|
||||
PostponedVariablesInitializerResolutionPart
|
||||
PostponedVariablesInitializerResolutionPart,
|
||||
CheckContextReceiversResolutionPart
|
||||
),
|
||||
INVOKE(*FUNCTION.resolutionSequence.toTypedArray()),
|
||||
CALLABLE_REFERENCE(
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
context(Int, String)
|
||||
fun foo(): String = "O"
|
||||
|
||||
context(Int)
|
||||
fun foo(): String = "K"
|
||||
|
||||
fun box(): String {
|
||||
val o = with ("") {
|
||||
with(42) {
|
||||
foo()
|
||||
}
|
||||
}
|
||||
val k = with(42) {
|
||||
foo()
|
||||
}
|
||||
return o + k
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
|
||||
<!CONFLICTING_OVERLOADS!>context(Int, String)
|
||||
fun foo(): Int<!> {
|
||||
return <!RETURN_TYPE_MISMATCH!>this<!UNRESOLVED_LABEL!>@Int<!> + 42<!>
|
||||
}
|
||||
|
||||
<!CONFLICTING_OVERLOADS!>context(Int)
|
||||
fun foo(): Int<!> {
|
||||
return <!RETURN_TYPE_MISMATCH!>this<!UNRESOLVED_LABEL!>@Int<!> + 42<!>
|
||||
}
|
||||
|
||||
fun test() {
|
||||
with(42) {
|
||||
foo()
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
|
||||
context(Int, String)
|
||||
fun foo(): Int {
|
||||
return this@Int + 42
|
||||
}
|
||||
|
||||
context(Int)
|
||||
fun foo(): Int {
|
||||
return this@Int + 42
|
||||
}
|
||||
|
||||
fun test() {
|
||||
with(42) {
|
||||
foo()
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Int
|
||||
public fun foo(): kotlin.Int
|
||||
public fun test(): kotlin.Unit
|
||||
Generated
+6
@@ -10654,6 +10654,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/overloadPriority.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloading.kt")
|
||||
public void testOverloading() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/overloading.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("plusMatrix.kt")
|
||||
public void testPlusMatrix() throws Exception {
|
||||
|
||||
+6
@@ -16181,6 +16181,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/overload.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloading.kt")
|
||||
public void testOverloading() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/overloading.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("plusAssign.kt")
|
||||
public void testPlusAssign() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user