diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 449709ae27d..47d26bc8463 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -27449,6 +27449,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/resolve/invoke"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform"); } + @Test + @TestMetadata("closeInvokesFarVariable.kt") + public void testCloseInvokesFarVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.kt"); + } + + @Test + @TestMetadata("closerVariableMatterMore.kt") + public void testCloserVariableMatterMore() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.kt"); + } + @Test @TestMetadata("completePropertyBeforeInvoke.kt") public void testCompletePropertyBeforeInvoke() throws Exception { @@ -27467,6 +27479,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt"); } + @Test + @TestMetadata("implicitAndInvokeExtensionPriority.kt") + public void testImplicitAndInvokeExtensionPriority() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.kt"); + } + @Test @TestMetadata("implicitInvoke.kt") public void testImplicitInvoke() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 028c1db7732..9b5d42ad073 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -27449,6 +27449,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/resolve/invoke"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform"); } + @Test + @TestMetadata("closeInvokesFarVariable.kt") + public void testCloseInvokesFarVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.kt"); + } + + @Test + @TestMetadata("closerVariableMatterMore.kt") + public void testCloserVariableMatterMore() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.kt"); + } + @Test @TestMetadata("completePropertyBeforeInvoke.kt") public void testCompletePropertyBeforeInvoke() throws Exception { @@ -27467,6 +27479,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt"); } + @Test + @TestMetadata("implicitAndInvokeExtensionPriority.kt") + public void testImplicitAndInvokeExtensionPriority() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.kt"); + } + @Test @TestMetadata("implicitInvoke.kt") public void testImplicitInvoke() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 4c9ee08fb17..28e2458cf03 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -27449,6 +27449,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/resolve/invoke"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform"); } + @Test + @TestMetadata("closeInvokesFarVariable.kt") + public void testCloseInvokesFarVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.kt"); + } + + @Test + @TestMetadata("closerVariableMatterMore.kt") + public void testCloserVariableMatterMore() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.kt"); + } + @Test @TestMetadata("completePropertyBeforeInvoke.kt") public void testCompletePropertyBeforeInvoke() throws Exception { @@ -27467,6 +27479,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt"); } + @Test + @TestMetadata("implicitAndInvokeExtensionPriority.kt") + public void testImplicitAndInvokeExtensionPriority() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.kt"); + } + @Test @TestMetadata("implicitInvoke.kt") public void testImplicitInvoke() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index e6b725938b6..34a28415a77 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -27461,6 +27461,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/resolve/invoke"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform"); } + @Test + @TestMetadata("closeInvokesFarVariable.kt") + public void testCloseInvokesFarVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.kt"); + } + + @Test + @TestMetadata("closerVariableMatterMore.kt") + public void testCloserVariableMatterMore() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.kt"); + } + @Test @TestMetadata("completePropertyBeforeInvoke.kt") public void testCompletePropertyBeforeInvoke() throws Exception { @@ -27479,6 +27491,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt"); } + @Test + @TestMetadata("implicitAndInvokeExtensionPriority.kt") + public void testImplicitAndInvokeExtensionPriority() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.kt"); + } + @Test @TestMetadata("implicitInvoke.kt") public void testImplicitInvoke() throws Exception { diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.fir.kt new file mode 100644 index 00000000000..2927aa5e3e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.fir.kt @@ -0,0 +1,17 @@ +// ISSUE: KT-37375 + +val foo: Any = Any() + +fun bar() { + operator fun Any.invoke(): String = "" + + fun baz() { + operator fun Any.invoke(): Int = 1 + + fun barbaz() { + takeInt(foo()) + } + } +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.kt b/compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.kt new file mode 100644 index 00000000000..8480c37646e --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.kt @@ -0,0 +1,17 @@ +// ISSUE: KT-37375 + +val foo: Any = Any() + +fun bar() { + operator fun Any.invoke(): String = "" + + fun baz() { + operator fun Any.invoke(): Int = 1 + + fun barbaz() { + takeInt(foo()) + } + } +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.fir.kt new file mode 100644 index 00000000000..4a53d7ec425 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.fir.kt @@ -0,0 +1,14 @@ +// ISSUE: KT-37375 + +fun takeDouble(x: Double) {} + +val bar: Int = 1 +operator fun Double.invoke(): Double = 1.0 // (1) + +fun test_1() { + val bar: Double = 2.0 + operator fun Int.invoke(): Int = 1 // (2) + + val res = bar() // should resolve to (1) + takeDouble(res) // should be OK +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.kt b/compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.kt new file mode 100644 index 00000000000..7f6c1ed84cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.kt @@ -0,0 +1,14 @@ +// ISSUE: KT-37375 + +fun takeDouble(x: Double) {} + +val bar: Int = 1 +operator fun Double.invoke(): Double = 1.0 // (1) + +fun test_1() { + val bar: Double = 2.0 + operator fun Int.invoke(): Int = 1 // (2) + + val res = bar() // should resolve to (1) + takeDouble(res) // should be OK +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.fir.kt new file mode 100644 index 00000000000..7110ae57a24 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.fir.kt @@ -0,0 +1,16 @@ +// ISSUE: KT-58943 + +class A { + fun bar() { + val foo: String.() -> Int = { 1 } // (1) + fun String.foo(): String = "" // (2) + with("2") { + // In K1, foo variable + invokeExtension on implicit receiver is more prioritized than `foo() + implicit receiver` + // So, for now, we're going to preserve that behavior in K2 + // For design, see KT-59528 + takeInt(foo()) + } + } +} + +fun takeInt(x: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.kt b/compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.kt new file mode 100644 index 00000000000..138c4c0dc23 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.kt @@ -0,0 +1,16 @@ +// ISSUE: KT-58943 + +class A { + fun bar() { + val foo: String.() -> Int = { 1 } // (1) + fun String.foo(): String = "" // (2) + with("2") { + // In K1, foo variable + invokeExtension on implicit receiver is more prioritized than `foo() + implicit receiver` + // So, for now, we're going to preserve that behavior in K2 + // For design, see KT-59528 + takeInt(foo()) + } + } +} + +fun takeInt(x: Int) {} \ No newline at end of file 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 78bcf25ee22..ae33e63aa31 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 @@ -28293,6 +28293,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/resolve/invoke"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); } + @Test + @TestMetadata("closeInvokesFarVariable.kt") + public void testCloseInvokesFarVariable() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closeInvokesFarVariable.kt"); + } + + @Test + @TestMetadata("closerVariableMatterMore.kt") + public void testCloserVariableMatterMore() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/closerVariableMatterMore.kt"); + } + @Test @TestMetadata("completePropertyBeforeInvoke.kt") public void testCompletePropertyBeforeInvoke() throws Exception { @@ -28311,6 +28323,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.kt"); } + @Test + @TestMetadata("implicitAndInvokeExtensionPriority.kt") + public void testImplicitAndInvokeExtensionPriority() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/invoke/implicitAndInvokeExtensionPriority.kt"); + } + @Test @TestMetadata("implicitInvoke.kt") public void testImplicitInvoke() throws Exception {