diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt index 6b9184ae885..574ae5e7b7c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallKind.kt @@ -17,7 +17,8 @@ enum class CallKind(vararg resolutionSequence: ResolutionStage) { SyntheticSelect( MapArguments, CreateFreshTypeVariableSubstitutorStage, - CheckArguments + CheckArguments, + EagerResolveOfCallableReferences ), Function( CheckVisibility, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt index 7e80d4212db..8752702c5db 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt @@ -185,6 +185,7 @@ internal object CheckArguments : CheckerStage() { internal object EagerResolveOfCallableReferences : CheckerStage() { override suspend fun check(candidate: Candidate, sink: CheckerSink, callInfo: CallInfo) { + if (candidate.postponedAtoms.isEmpty()) return for (atom in candidate.postponedAtoms.filterIsInstance()) { if (!candidate.bodyResolveComponents.callResolver.resolveCallableReference(candidate.csBuilder, atom)) { sink.yieldApplicability(CandidateApplicability.INAPPLICABLE) diff --git a/compiler/fir/resolve/testData/resolve/problems/callableReferenceOnInstance.kt b/compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.kt similarity index 66% rename from compiler/fir/resolve/testData/resolve/problems/callableReferenceOnInstance.kt rename to compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.kt index bf2bb4d0fde..2408b57fc44 100644 --- a/compiler/fir/resolve/testData/resolve/problems/callableReferenceOnInstance.kt +++ b/compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.kt @@ -7,7 +7,7 @@ interface KaptLogger { fun test(logger: KaptLogger) { val func = if (logger.isVerbose) - logger::warn + logger::warn else - logger::error -} \ No newline at end of file + logger::error +} diff --git a/compiler/fir/resolve/testData/resolve/problems/callableReferenceOnInstance.txt b/compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.txt similarity index 73% rename from compiler/fir/resolve/testData/resolve/problems/callableReferenceOnInstance.txt rename to compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.txt index 1db14b09632..05ef0820637 100644 --- a/compiler/fir/resolve/testData/resolve/problems/callableReferenceOnInstance.txt +++ b/compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.txt @@ -9,12 +9,12 @@ FILE: callableReferenceOnInstance.kt } public final fun test(logger: R|KaptLogger|): R|kotlin/Unit| { - lval func: R|kotlin/Nothing| = when () { + lval func: R|kotlin/reflect/KFunction1| = when () { R|/logger|.R|/KaptLogger.isVerbose| -> { - R|/logger|::# + R|/logger|::R|/KaptLogger.warn| } else -> { - R|/logger|::# + R|/logger|::R|/KaptLogger.error| } } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/callableReferences/ifWithCR.kt b/compiler/fir/resolve/testData/resolve/stdlib/callableReferences/ifWithCR.kt new file mode 100644 index 00000000000..d74affe830e --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/callableReferences/ifWithCR.kt @@ -0,0 +1,8 @@ +private var Int.readOnlyWrapper: CharSequence? get() = null +private var Int.mutableWrapper: CharSequence? get() = null + +fun main(x: Int) { + val x = if (x > 1) x::readOnlyWrapper else x::mutableWrapper + + x.get() +} diff --git a/compiler/fir/resolve/testData/resolve/stdlib/callableReferences/ifWithCR.txt b/compiler/fir/resolve/testData/resolve/stdlib/callableReferences/ifWithCR.txt new file mode 100644 index 00000000000..6121638a0ec --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/callableReferences/ifWithCR.txt @@ -0,0 +1,23 @@ +FILE: ifWithCR.kt + private final var R|kotlin/Int|.readOnlyWrapper: R|kotlin/CharSequence?| + public get(): R|kotlin/CharSequence?| { + ^ Null(null) + } + private set(value: R|kotlin/CharSequence?|): R|kotlin/Unit| + private final var R|kotlin/Int|.mutableWrapper: R|kotlin/CharSequence?| + public get(): R|kotlin/CharSequence?| { + ^ Null(null) + } + private set(value: R|kotlin/CharSequence?|): R|kotlin/Unit| + public final fun main(x: R|kotlin/Int|): R|kotlin/Unit| { + lval x: R|kotlin/reflect/KMutableProperty0| = when () { + >(R|/x|, Int(1)) -> { + R|/x|::R|/readOnlyWrapper| + } + else -> { + R|/x|::R|/mutableWrapper| + } + } + + R|/x|.R|FakeOverride|() + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 728bde9f151..7bc3991ead6 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -919,6 +919,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/resolve/testData/resolve/inference"), Pattern.compile("^([^.]+)\\.kt$"), null, true); } + @TestMetadata("callableReferenceOnInstance.kt") + public void testCallableReferenceOnInstance() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.kt"); + } + @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() throws Exception { runTest("compiler/fir/resolve/testData/resolve/inference/nestedLambdas.kt"); @@ -1106,11 +1111,6 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/problems/bareTypes.kt"); } - @TestMetadata("callableReferenceOnInstance.kt") - public void testCallableReferenceOnInstance() throws Exception { - runTest("compiler/fir/resolve/testData/resolve/problems/callableReferenceOnInstance.kt"); - } - @TestMetadata("covariantArrayAsReceiver.kt") public void testCovariantArrayAsReceiver() throws Exception { runTest("compiler/fir/resolve/testData/resolve/problems/covariantArrayAsReceiver.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index f3fdf0016b3..2211ec351ee 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -919,6 +919,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/resolve/testData/resolve/inference"), Pattern.compile("^([^.]+)\\.kt$"), null, true); } + @TestMetadata("callableReferenceOnInstance.kt") + public void testCallableReferenceOnInstance() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.kt"); + } + @TestMetadata("nestedLambdas.kt") public void testNestedLambdas() throws Exception { runTest("compiler/fir/resolve/testData/resolve/inference/nestedLambdas.kt"); @@ -1106,11 +1111,6 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/resolve/testData/resolve/problems/bareTypes.kt"); } - @TestMetadata("callableReferenceOnInstance.kt") - public void testCallableReferenceOnInstance() throws Exception { - runTest("compiler/fir/resolve/testData/resolve/problems/callableReferenceOnInstance.kt"); - } - @TestMetadata("covariantArrayAsReceiver.kt") public void testCovariantArrayAsReceiver() throws Exception { runTest("compiler/fir/resolve/testData/resolve/problems/covariantArrayAsReceiver.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index 291f0b055c8..59913938f8e 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -295,6 +295,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic runTest("compiler/fir/resolve/testData/resolve/stdlib/callableReferences/extensionReceiverInference.kt"); } + @TestMetadata("ifWithCR.kt") + public void testIfWithCR() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/stdlib/callableReferences/ifWithCR.kt"); + } + @TestMetadata("implicitTypes.kt") public void testImplicitTypes() throws Exception { runTest("compiler/fir/resolve/testData/resolve/stdlib/callableReferences/implicitTypes.kt"); diff --git a/compiler/testData/codegen/box/callableReference/function/specialCalls.kt b/compiler/testData/codegen/box/callableReference/function/specialCalls.kt index 562b8d32716..203351c48d8 100644 --- a/compiler/testData/codegen/box/callableReference/function/specialCalls.kt +++ b/compiler/testData/codegen/box/callableReference/function/specialCalls.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun baz(i: Int) = i fun bar(x: T): T = x @@ -27,4 +26,4 @@ fun box(): String { if ((if (true) ::baz else ::baz)(1) != 1) return "fail 6" return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.fir.kt b/compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.fir.kt index a70957b6ada..a0fbbd4e5fc 100644 --- a/compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/callableReferenceAsLastExpressionInBlock.fir.kt @@ -7,11 +7,11 @@ fun test() { val a = if (true) { val x = 1 "".length - ::foo + ::foo } else { - ::foo + ::foo } a checkType { _>() } } -fun foo(): Int = 0 \ No newline at end of file +fun foo(): Int = 0 diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt index 1d2645d1bfc..1c68ab510fd 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/specialCalls.fir.kt @@ -6,18 +6,18 @@ fun bar(x: T): T = TODO() fun nullableFun(): ((Int) -> Int)? = null fun test() { - val x1: (Int) -> Int = bar(if (true) ::baz else ::baz) - val x2: (Int) -> Int = bar(nullableFun() ?: ::baz) - val x3: (Int) -> Int = bar(::baz ?: ::baz) + val x1: (Int) -> Int = bar(if (true) ::baz else ::baz) + val x2: (Int) -> Int = bar(nullableFun() ?: ::baz) + val x3: (Int) -> Int = bar(::baz ?: ::baz) val i = 0 val x4: (Int) -> Int = bar(when (i) { - 10 -> ::baz - 20 -> ::baz - else -> ::baz + 10 -> ::baz + 20 -> ::baz + else -> ::baz }) - val x5: (Int) -> Int = bar(::baz!!) + val x5: (Int) -> Int = bar(::baz!!) - (if (true) ::baz else ::baz)(1) -} \ No newline at end of file + (if (true) ::baz else ::baz)(1) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.fir.kt index d684aa7cc51..8699a7993e5 100644 --- a/compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/kt15439_completeCall.fir.kt @@ -2,10 +2,10 @@ fun test() { data class Pair(val first: F, val second: S) - val (x, y) = - Pair(1, + val (x, y) = + Pair(1, if (1 == 1) - Pair::first + Pair::first else - Pair::second) -} \ No newline at end of file + Pair::second) +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/kt8596.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/kt8596.fir.kt index fed7c090b75..393f4b28250 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/kt8596.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/kt8596.fir.kt @@ -18,8 +18,8 @@ class Foo(val a: String, val b: String) fun test2() { val prop : Foo.() -> String = if (true) { - Foo::a + Foo::a } else { - Foo::b + Foo::b } } diff --git a/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt b/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt index da3429d6c5e..c9b2f2f93af 100644 --- a/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/callableReferenceInCST.fir.kt @@ -4,33 +4,33 @@ fun testWhen(x: Any?) { val y = when (x) { null -> "" - else -> ::unresolved + else -> ::unresolved } } fun testWhenWithBraces(x: Any?) { val z = when(x) { null -> { "" } - else -> { ::unresolved } + else -> { ::unresolved } } } fun testIf(x: Any?) { - val y = if (x != null) ::unresolved else null + val y = if (x != null) ::unresolved else null } fun testIfWithBraces(x: Any?) { - val z = if (x != null) { ::unresolved } else { null } + val z = if (x != null) { ::unresolved } else { null } } fun testElvis(x: Any?) { - val y = x ?: ::unresolved + val y = x ?: ::unresolved } fun testExclExcl() { - val y = :: unresolved!! + val y = :: unresolved!! } fun testTry() { - val v = try { ::unresolved } catch (e: Exception) {} + val v = try { ::unresolved } catch (e: Exception) {} }