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 7e0a8cc536b..6ece4bcb6e5 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 @@ -39239,6 +39239,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt"); } + @Test + @TestMetadata("lowPriorityTopLevelValAndObject.kt") + public void testLowPriorityTopLevelValAndObject() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/lowPriorityTopLevelValAndObject.kt"); + } + @Test @TestMetadata("moreOnlyInputTypes.kt") public void testMoreOnlyInputTypes() 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 32022683bcd..93bf3080aae 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 @@ -39239,6 +39239,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt"); } + @Test + @TestMetadata("lowPriorityTopLevelValAndObject.kt") + public void testLowPriorityTopLevelValAndObject() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/lowPriorityTopLevelValAndObject.kt"); + } + @Test @TestMetadata("moreOnlyInputTypes.kt") public void testMoreOnlyInputTypes() 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 bdbf039ce28..0b7a26fe924 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 @@ -39239,6 +39239,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt"); } + @Test + @TestMetadata("lowPriorityTopLevelValAndObject.kt") + public void testLowPriorityTopLevelValAndObject() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/lowPriorityTopLevelValAndObject.kt"); + } + @Test @TestMetadata("moreOnlyInputTypes.kt") public void testMoreOnlyInputTypes() 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 a08cec491b6..8f4243be48f 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 @@ -39335,6 +39335,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt"); } + @Test + @TestMetadata("lowPriorityTopLevelValAndObject.kt") + public void testLowPriorityTopLevelValAndObject() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/lowPriorityTopLevelValAndObject.kt"); + } + @Test @TestMetadata("moreOnlyInputTypes.kt") public void testMoreOnlyInputTypes() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt index 2b1165be5a5..0bea064ceec 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt @@ -51,7 +51,7 @@ open class CandidateCollector( open fun shouldStopAtTheGroup(group: TowerGroup): Boolean = shouldStopResolve && bestGroup < group - private val shouldStopResolve: Boolean + val shouldStopResolve: Boolean get() = currentApplicability.shouldStopResolve val isSuccess: Boolean diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt index a02837bb152..cd114fb94cb 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind +import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability internal class CandidateFactoriesAndCollectors( // Common calls @@ -45,7 +46,11 @@ internal class TowerLevelHandler { CallKind.VariableAccess -> { processResult += towerLevel.processPropertiesByName(info, processor) - if (!collector.isSuccess && towerLevel is ScopeTowerLevel && !towerLevel.areThereExtensionReceiverOptions()) { + // Top-level properties win over objects. Therefore, if we find properties, we don't want to look for objects here. + // However, this only applies if the best current candidate applicability has shouldStopResolve == true. Exceptions to this + // are candidates from dynamic scopes or properties with @LowPriorityInOverloadResolution (from earlier or the same level), + // therefore we check for collector.shouldStopResolve and not collector.isSuccess. + if (!collector.shouldStopResolve && towerLevel is ScopeTowerLevel && !towerLevel.areThereExtensionReceiverOptions()) { processResult += towerLevel.processObjectsByName(info, processor) } } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/kt57960.fir.txt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/kt57960.fir.txt new file mode 100644 index 00000000000..8d96815b584 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/kt57960.fir.txt @@ -0,0 +1,52 @@ +FILE: kt57960.kt + public final class Bar : R|kotlin/Any| { + public constructor(): R|Bar| { + super() + } + + public final var toDOM: R|((Baz) -> kotlin/Any)?| = Null(null) + public get(): R|((Baz) -> kotlin/Any)?| + public set(value: R|((Baz) -> kotlin/Any)?|): R|kotlin/Unit| + + } + public final class Baz : R|kotlin/Any| { + public constructor(): R|Baz| { + super() + } + + public final var text: R|kotlin/String| = String() + public get(): R|kotlin/String| + public set(value: R|kotlin/String|): R|kotlin/Unit| + + } + public final object Foo : R|kotlin/Any| { + private constructor(): R|Foo| { + super() + } + + public final fun create2(toDOM: R|((Baz) -> kotlin/Any)?| = Null(null)): R|Bar| { + ^create2 R|/jso|( = jso@fun R|Bar|.(): R|kotlin/Unit| { + R|/toDOM|?.{ $subj$.R|kotlin/let| kotlin/Any|, R|kotlin/Unit|>( = let@fun (it: R|(Baz) -> kotlin/Any|): R|kotlin/Unit| { + this@R|special/anonymous|.R|/Bar.toDOM| = R|/it| + } + ) } + } + ) + } + + } + private final fun buildSchemaNodes1(): R|kotlin/Unit| { + R|/jso|( = jso@fun R|dynamic|.(): R|kotlin/Unit| { + Q|Foo|.R|/Foo.create2|(toDOM = create2@fun (domNode: R|Baz|): R|kotlin/Any| { + ^ R|/domNode|.R|/Baz.text| + } + ) + } + ) + } + public final fun jso(): R|T| { + ^jso R|kotlin/js/js|(String(({}))) + } + public final inline fun jso(block: R|T.() -> kotlin/Unit|): R|T| { + ^jso R|/jso|().R|kotlin/apply|(R|/block|) + } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/kt57960.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/kt57960.kt new file mode 100644 index 00000000000..f39d993b5a2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/kt57960.kt @@ -0,0 +1,34 @@ +// FIR_IDENTICAL +// FIR_DUMP +// ISSUE: KT-57960 + +class Bar { + var toDOM: ((Baz) -> Any)? = null +} + +class Baz { + var text: String = "" +} + +object Foo { + fun create2( + toDOM: ((Baz) -> Any)? = null, + ) = jso { + toDOM?.let { this.toDOM = it } + } +} + +private fun buildSchemaNodes1() { + jso { + Foo.create2(toDOM = { domNode -> domNode.text }) + } +} + + +fun jso(): T = + js("({})") + +inline fun jso( + block: T.() -> Unit, +): T = + jso().apply(block) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/objectAccessInLambdaWithDynamicReceiver.fir.txt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/objectAccessInLambdaWithDynamicReceiver.fir.txt new file mode 100644 index 00000000000..9fb6b5b97c8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/objectAccessInLambdaWithDynamicReceiver.fir.txt @@ -0,0 +1,27 @@ +FILE: objectAccessInLambdaWithDynamicReceiver.kt + public final fun jso(block: R|dynamic.() -> kotlin/Unit|): R|dynamic| { + ^jso R|kotlin/js/js|(String(({}))).R|/apply|(vararg(R|/block|)) + } + public final class G : R|kotlin/Any| { + public constructor(): R|G| { + super() + } + + public final companion object Companion : R|kotlin/Any| { + private constructor(): R|G.Companion| { + super() + } + + public final val foo: R|kotlin/String| = String(string) + public get(): R|kotlin/String| + + } + + } + public final fun test(): R|kotlin/Unit| { + R|/jso|( = jso@fun R|dynamic|.(): R|kotlin/Unit| { + R|/G.G|() + Q|G|.R|/G.Companion.foo| + } + ) + } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/objectAccessInLambdaWithDynamicReceiver.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/objectAccessInLambdaWithDynamicReceiver.kt new file mode 100644 index 00000000000..57f024fed8f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/objectAccessInLambdaWithDynamicReceiver.kt @@ -0,0 +1,17 @@ +// FIR_IDENTICAL +// FIR_DUMP + +fun jso(block: dynamic.() -> Unit): dynamic = js("({})").apply(block) + +class G { + companion object { + val foo = "string" + } +} + +fun test() { + jso { + G() + G.foo + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/lowPriorityTopLevelValAndObject.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/lowPriorityTopLevelValAndObject.kt new file mode 100644 index 00000000000..f6bd131007e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/lowPriorityTopLevelValAndObject.kt @@ -0,0 +1,37 @@ +// FIR_IDENTICAL +// DIAGNOSTICS: -EXTENSION_SHADOWED_BY_MEMBER + +// FILE: a.kt +package a + +val bar get() = "" + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@kotlin.internal.LowPriorityInOverloadResolution +val baz get() = "" + +// FILE: b.kt +package b + +object bar +object baz { + val qux = 1 +} + +// FILE: test.kt +import a.* +import b.* + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +class Foo { + @kotlin.internal.LowPriorityInOverloadResolution + val bar = 1 + + @kotlin.internal.LowPriorityInOverloadResolution + val baz = 1 +} + +fun Foo.test() { + bar.length + baz.qux +} \ 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 3058aa73935..a59a54b96da 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 @@ -40107,6 +40107,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt"); } + @Test + @TestMetadata("lowPriorityTopLevelValAndObject.kt") + public void testLowPriorityTopLevelValAndObject() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/lowPriorityTopLevelValAndObject.kt"); + } + @Test @TestMetadata("moreOnlyInputTypes.kt") public void testMoreOnlyInputTypes() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJsStdLibGenerated.java index c31eca31af0..c80e2b6b2c9 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJsStdLibGenerated.java @@ -289,6 +289,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inference.kt"); } + @Test + @TestMetadata("kt57960.kt") + public void testKt57960() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/kt57960.kt"); + } + @Test @TestMetadata("membersOfAny.kt") public void testMembersOfAny() throws Exception { @@ -313,6 +319,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/nullable.kt"); } + @Test + @TestMetadata("objectAccessInLambdaWithDynamicReceiver.kt") + public void testObjectAccessInLambdaWithDynamicReceiver() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/objectAccessInLambdaWithDynamicReceiver.kt"); + } + @Test @TestMetadata("overloading.kt") public void testOverloading() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsOldFrontendDiagnosticsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsOldFrontendDiagnosticsTestGenerated.java index 746e95c0469..99f36d0f4aa 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsOldFrontendDiagnosticsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsOldFrontendDiagnosticsTestGenerated.java @@ -290,6 +290,12 @@ public class FirPsiJsOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiJ runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inference.kt"); } + @Test + @TestMetadata("kt57960.kt") + public void testKt57960() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/kt57960.kt"); + } + @Test @TestMetadata("membersOfAny.kt") public void testMembersOfAny() throws Exception { @@ -314,6 +320,12 @@ public class FirPsiJsOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiJ runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/nullable.kt"); } + @Test + @TestMetadata("objectAccessInLambdaWithDynamicReceiver.kt") + public void testObjectAccessInLambdaWithDynamicReceiver() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/objectAccessInLambdaWithDynamicReceiver.kt"); + } + @Test @TestMetadata("overloading.kt") public void testOverloading() throws Exception {