[FIR] Set correct constraint position for callable reference
This fixes a false positive resolution error for callable references to functions with a type parameter that's annotated with @OnlyInputTypes. #KT-57994 Fixed
This commit is contained in:
committed by
Space Team
parent
89acaae819
commit
7f46225bed
+6
@@ -4223,6 +4223,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onlyInputTypesOnCallableReference.kt")
|
||||
public void testOnlyInputTypesOnCallableReference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/onlyInputTypesOnCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadAmbiguityForSimpleLastExpressionOfBlock.kt")
|
||||
public void testOverloadAmbiguityForSimpleLastExpressionOfBlock() throws Exception {
|
||||
|
||||
+6
@@ -4223,6 +4223,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onlyInputTypesOnCallableReference.kt")
|
||||
public void testOnlyInputTypesOnCallableReference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/onlyInputTypesOnCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadAmbiguityForSimpleLastExpressionOfBlock.kt")
|
||||
public void testOverloadAmbiguityForSimpleLastExpressionOfBlock() throws Exception {
|
||||
|
||||
+6
@@ -4223,6 +4223,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onlyInputTypesOnCallableReference.kt")
|
||||
public void testOnlyInputTypesOnCallableReference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/onlyInputTypesOnCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadAmbiguityForSimpleLastExpressionOfBlock.kt")
|
||||
public void testOverloadAmbiguityForSimpleLastExpressionOfBlock() throws Exception {
|
||||
|
||||
+6
@@ -4229,6 +4229,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onlyInputTypesOnCallableReference.kt")
|
||||
public void testOnlyInputTypesOnCallableReference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/onlyInputTypesOnCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadAmbiguityForSimpleLastExpressionOfBlock.kt")
|
||||
public void testOverloadAmbiguityForSimpleLastExpressionOfBlock() throws Exception {
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.resolve.DoubleColonLHS
|
||||
import org.jetbrains.kotlin.fir.resolve.createFunctionType
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedCallableReferenceTarget
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.extractInputOutputTypesFromCallableReferenceExpectedType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeArgumentConstraintPosition
|
||||
import org.jetbrains.kotlin.fir.resolve.scope
|
||||
import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
@@ -30,7 +31,6 @@ import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.runTransaction
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||
import org.jetbrains.kotlin.types.expressions.CoercionStrategy
|
||||
@@ -64,7 +64,8 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() {
|
||||
candidate.outerConstraintBuilderEffect = fun ConstraintSystemOperation.() {
|
||||
addOtherSystem(candidate.system.currentStorage())
|
||||
|
||||
val position = SimpleConstraintSystemConstraintPosition //TODO
|
||||
// Callable references are either arguments to a call or are wrapped in a synthetic call for resolution.
|
||||
val position = ConeArgumentConstraintPosition(callInfo.callSite)
|
||||
|
||||
if (expectedType != null && !resultingType.contains {
|
||||
it is ConeTypeVariableType && it.lookupTag !in outerCsBuilder.currentStorage().allTypeVariables
|
||||
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
// WITH_STDLIB
|
||||
|
||||
open class BaseClass
|
||||
class DerivedClass : BaseClass()
|
||||
|
||||
fun test() {
|
||||
val derivedToStringMap: Map<DerivedClass, String> = mapOf()
|
||||
val mapper: (BaseClass) -> String? = derivedToStringMap::get
|
||||
|
||||
foo(mapper)
|
||||
foo(derivedToStringMap::get)
|
||||
}
|
||||
|
||||
|
||||
fun foo(mapper: (BaseClass) -> String?) {}
|
||||
Generated
+6
@@ -4229,6 +4229,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("onlyInputTypesOnCallableReference.kt")
|
||||
public void testOnlyInputTypesOnCallableReference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/callableReference/resolve/onlyInputTypesOnCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overloadAmbiguityForSimpleLastExpressionOfBlock.kt")
|
||||
public void testOverloadAmbiguityForSimpleLastExpressionOfBlock() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user