diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 0d343bb9c98..de59f2092a5 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -10600,6 +10600,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/ambiguityInGroup.kt"); } + @Test + @TestMetadata("conflicting.kt") + public void testConflicting() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.kt"); + } + + @Test + @TestMetadata("conflictingWithDifferentOrder.kt") + public void testConflictingWithDifferentOrder() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.kt"); + } + @Test @TestMetadata("contextKeywordWithElvis.kt") public void testContextKeywordWithElvis() throws Exception { @@ -10684,6 +10696,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noLabelsByClassName.kt"); } + @Test + @TestMetadata("nonConflicting.kt") + public void testNonConflicting() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.kt"); + } + @Test @TestMetadata("outerClass.kt") public void testOuterClass() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index bb96f0ae5c7..6abdca9127b 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -10600,6 +10600,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/ambiguityInGroup.kt"); } + @Test + @TestMetadata("conflicting.kt") + public void testConflicting() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.kt"); + } + + @Test + @TestMetadata("conflictingWithDifferentOrder.kt") + public void testConflictingWithDifferentOrder() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.kt"); + } + @Test @TestMetadata("contextKeywordWithElvis.kt") public void testContextKeywordWithElvis() throws Exception { @@ -10684,6 +10696,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noLabelsByClassName.kt"); } + @Test + @TestMetadata("nonConflicting.kt") + public void testNonConflicting() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.kt"); + } + @Test @TestMetadata("outerClass.kt") public void testOuterClass() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 33fbddd455c..5971b75e3e8 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -10600,6 +10600,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/ambiguityInGroup.kt"); } + @Test + @TestMetadata("conflicting.kt") + public void testConflicting() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.kt"); + } + + @Test + @TestMetadata("conflictingWithDifferentOrder.kt") + public void testConflictingWithDifferentOrder() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.kt"); + } + @Test @TestMetadata("contextKeywordWithElvis.kt") public void testContextKeywordWithElvis() throws Exception { @@ -10684,6 +10696,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noLabelsByClassName.kt"); } + @Test + @TestMetadata("nonConflicting.kt") + public void testNonConflicting() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.kt"); + } + @Test @TestMetadata("outerClass.kt") public void testOuterClass() throws Exception { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignature.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignature.kt index 4430bff65e9..2bafccf916a 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignature.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignature.kt @@ -66,11 +66,19 @@ private fun SimpleConstraintSystem.isValueParameterTypeNotLessSpecific( ): Boolean { val typeParameters = general.typeParameters val typeSubstitutor = registerTypeVariables(typeParameters) - val valueParamsWithoutContextReceivers = - specific.valueParameterTypes.drop(specific.contextReceiverCount).map(typeKindSelector) - .zip(general.valueParameterTypes.drop(general.contextReceiverCount).map(typeKindSelector)) - for ((specificType, generalType) in valueParamsWithoutContextReceivers) { + val specificContextReceiverCount = specific.contextReceiverCount + val generalContextReceiverCount = general.contextReceiverCount + + var specificValueParameterTypes = specific.valueParameterTypes + var generalValueParameterTypes = general.valueParameterTypes + if (specificContextReceiverCount != generalContextReceiverCount) { + specificValueParameterTypes = specificValueParameterTypes.drop(specificContextReceiverCount) + generalValueParameterTypes = generalValueParameterTypes.drop(generalContextReceiverCount) + } + val valueParameters = specificValueParameterTypes.map(typeKindSelector).zip(generalValueParameterTypes.map(typeKindSelector)) + + for ((specificType, generalType) in valueParameters) { if (specificType == null || generalType == null) continue if (specificityComparator.isDefinitelyLessSpecific(specificType, generalType)) { diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.fir.kt new file mode 100644 index 00000000000..17a407a0c62 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ContextReceivers + +interface A +interface B + +context(A, B) +fun f(): Unit = TODO() + +context(A, B) +fun f(): Unit = TODO() + +fun test(a: A, b: B) { + with(a) { + with(b) { + f() + } + } +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.kt new file mode 100644 index 00000000000..d39b9b6d258 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ContextReceivers + +interface A +interface B + +context(A, B) +fun f(): Unit = TODO() + +context(A, B) +fun f(): Unit = TODO() + +fun test(a: A, b: B) { + with(a) { + with(b) { + f() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.txt new file mode 100644 index 00000000000..103dc1b1da1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.txt @@ -0,0 +1,17 @@ +package + +context(A, B) public fun f(): kotlin.Unit +context(A, B) public fun f(): kotlin.Unit +public fun test(/*0*/ a: A, /*1*/ b: B): kotlin.Unit + +public interface A { + 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 B { + 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/extensions/contextReceivers/conflictingWithDifferentOrder.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.fir.kt new file mode 100644 index 00000000000..e8ff6f7d8dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ContextReceivers + +interface A +interface B + +context(A, B) +fun f(): Unit = TODO() + +context(B, A) +fun f(): Unit = TODO() + +fun test(a: A, b: B) { + with(a) { + with(b) { + f() + } + } +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.kt new file mode 100644 index 00000000000..7fc08839989 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +ContextReceivers + +interface A +interface B + +context(A, B) +fun f(): Unit = TODO() + +context(B, A) +fun f(): Unit = TODO() + +fun test(a: A, b: B) { + with(a) { + with(b) { + f() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.txt new file mode 100644 index 00000000000..5c988b8dead --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.txt @@ -0,0 +1,17 @@ +package + +context(A, B) public fun f(): kotlin.Unit +context(B, A) public fun f(): kotlin.Unit +public fun test(/*0*/ a: A, /*1*/ b: B): kotlin.Unit + +public interface A { + 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 B { + 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/extensions/contextReceivers/nonConflicting.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.fir.kt new file mode 100644 index 00000000000..4a63953f829 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.fir.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +ContextReceivers + +interface A +interface B +interface C +interface D + +context(A, B) +fun f(): Unit = TODO() + +context(C, D) +fun f(): Unit = TODO() + +fun test(a: A, b: B) { + with(a) { + with(b) { + f() + } + } +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.kt new file mode 100644 index 00000000000..5d05d2dc984 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.kt @@ -0,0 +1,20 @@ +// !LANGUAGE: +ContextReceivers + +interface A +interface B +interface C +interface D + +context(A, B) +fun f(): Unit = TODO() + +context(C, D) +fun f(): Unit = TODO() + +fun test(a: A, b: B) { + with(a) { + with(b) { + f() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.txt new file mode 100644 index 00000000000..8869659b5d6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.txt @@ -0,0 +1,29 @@ +package + +context(A, B) public fun f(): kotlin.Unit +context(C, D) public fun f(): kotlin.Unit +public fun test(/*0*/ a: A, /*1*/ b: B): kotlin.Unit + +public interface A { + 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 B { + 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 C { + 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 D { + 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-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 60429b3df38..ea003f47870 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -10606,6 +10606,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/ambiguityInGroup.kt"); } + @Test + @TestMetadata("conflicting.kt") + public void testConflicting() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/conflicting.kt"); + } + + @Test + @TestMetadata("conflictingWithDifferentOrder.kt") + public void testConflictingWithDifferentOrder() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/conflictingWithDifferentOrder.kt"); + } + @Test @TestMetadata("contextKeywordWithElvis.kt") public void testContextKeywordWithElvis() throws Exception { @@ -10690,6 +10702,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noLabelsByClassName.kt"); } + @Test + @TestMetadata("nonConflicting.kt") + public void testNonConflicting() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/nonConflicting.kt"); + } + @Test @TestMetadata("outerClass.kt") public void testOuterClass() throws Exception {