[FIR] Fix callable reference adaptation for overrides without defaults
Provide the correct scope to the argument mapping so that default values in overridden functions are considered. ^KT-56864 Fixed
This commit is contained in:
committed by
Space Team
parent
9d352694af
commit
b2fbf8bed5
+6
@@ -3166,6 +3166,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("adaptationToOverridenWithoutDefault.kt")
|
||||||
|
public void testAdaptationToOverridenWithoutDefault() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationToOverridenWithoutDefault.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInAdapted() throws Exception {
|
public void testAllFilesPresentInAdapted() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||||
|
|||||||
+6
@@ -3166,6 +3166,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("adaptationToOverridenWithoutDefault.kt")
|
||||||
|
public void testAdaptationToOverridenWithoutDefault() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationToOverridenWithoutDefault.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInAdapted() throws Exception {
|
public void testAllFilesPresentInAdapted() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||||
|
|||||||
+6
@@ -3172,6 +3172,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("adaptationToOverridenWithoutDefault.kt")
|
||||||
|
public void testAdaptationToOverridenWithoutDefault() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationToOverridenWithoutDefault.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInAdapted() throws Exception {
|
public void testAllFilesPresentInAdapted() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||||
|
|||||||
+5
-2
@@ -22,6 +22,8 @@ import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS
|
|||||||
import org.jetbrains.kotlin.fir.resolve.createFunctionType
|
import org.jetbrains.kotlin.fir.resolve.createFunctionType
|
||||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedCallableReferenceTarget
|
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedCallableReferenceTarget
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.extractInputOutputTypesFromCallableReferenceExpectedType
|
import org.jetbrains.kotlin.fir.resolve.inference.extractInputOutputTypesFromCallableReferenceExpectedType
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.scope
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
@@ -173,8 +175,9 @@ private fun BodyResolveComponents.getCallableReferenceAdaptation(
|
|||||||
if (expectedArgumentsCount < 0) return null
|
if (expectedArgumentsCount < 0) return null
|
||||||
|
|
||||||
val fakeArguments = createFakeArgumentsForReference(function, expectedArgumentsCount, inputTypes, unboundReceiverCount)
|
val fakeArguments = createFakeArgumentsForReference(function, expectedArgumentsCount, inputTypes, unboundReceiverCount)
|
||||||
// TODO: Use correct originScope
|
val originScope = function.dispatchReceiverType
|
||||||
val argumentMapping = mapArguments(fakeArguments, function, originScope = null, callSiteIsOperatorCall = false)
|
?.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS)
|
||||||
|
val argumentMapping = mapArguments(fakeArguments, function, originScope = originScope, callSiteIsOperatorCall = false)
|
||||||
if (argumentMapping.diagnostics.any { !it.applicability.isSuccess }) return null
|
if (argumentMapping.diagnostics.any { !it.applicability.isSuccess }) return null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
compiler/testData/diagnostics/tests/callableReference/adapted/adaptationToOverridenWithoutDefault.kt
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
// SKIP_TXT
|
||||||
|
// FIR_IDENTICAL
|
||||||
|
|
||||||
|
interface Some {
|
||||||
|
fun foo(b: Boolean? = null): Int = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
class SomeImpl : Some {
|
||||||
|
override fun foo(b: Boolean?): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buz() {
|
||||||
|
bar(::foo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buz() {
|
||||||
|
bar(SomeImpl()::foo)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T> bar(actionForAll: () -> T) {
|
||||||
|
actionForAll()
|
||||||
|
}
|
||||||
Generated
+6
@@ -3172,6 +3172,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt");
|
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationInWhenWithMapOf.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("adaptationToOverridenWithoutDefault.kt")
|
||||||
|
public void testAdaptationToOverridenWithoutDefault() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/callableReference/adapted/adaptationToOverridenWithoutDefault.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInAdapted() throws Exception {
|
public void testAllFilesPresentInAdapted() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/callableReference/adapted"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(fir|ll)\\.kts?$"), true);
|
||||||
|
|||||||
Reference in New Issue
Block a user