[FIR] Set source on callee reference of implicit invoke receiver

This fixes an IllegalArgumentException when a diagnostic was reported on
it because no source was set.

#KT-61829 Fixed
This commit is contained in:
Kirill Rakhman
2023-09-13 12:08:36 +02:00
committed by Space Team
parent a224f9db34
commit ce65d3c7b8
7 changed files with 45 additions and 2 deletions
@@ -3847,6 +3847,12 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag
runTest("compiler/fir/analysis-tests/testData/resolve/problems/incompleteWhen.kt");
}
@Test
@TestMetadata("incorrectGenericLambdaProperty.kt")
public void testIncorrectGenericLambdaProperty() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt");
}
@Test
@TestMetadata("innerClassHierarchy.kt")
public void testInnerClassHierarchy() throws Exception {
@@ -3847,6 +3847,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated
runTest("compiler/fir/analysis-tests/testData/resolve/problems/incompleteWhen.kt");
}
@Test
@TestMetadata("incorrectGenericLambdaProperty.kt")
public void testIncorrectGenericLambdaProperty() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt");
}
@Test
@TestMetadata("innerClassHierarchy.kt")
public void testInnerClassHierarchy() throws Exception {
@@ -0,0 +1,13 @@
FILE: incorrectGenericLambdaProperty.kt
public final fun main(args: R|kotlin/Array<kotlin/String>|): R|kotlin/Unit| {
lval <T> passIt: R|(ERROR CLASS: No type for parameter) -> ERROR CLASS: Symbol not found for T| = fun <anonymous>(<destruct>: <ERROR TYPE REF: No type for parameter>): <ERROR TYPE REF: Symbol not found for T> <inline=Unknown> {
lval t: <ERROR TYPE REF: Symbol not found for T> = R|<local>/<destruct>|.<Unresolved name: component1>#()
^ {
R|<local>/t|
}
}
R|<local>/passIt<CS errors: <local>/passIt>#|<<ERROR TYPE REF: Cannot infer argument for type parameter T>>.R|SubstitutionOverride<kotlin/Function1.invoke: <ERROR TYPE REF: Symbol not found for T>><Inapplicable(INAPPLICABLE): kotlin/Function1.invoke>#|<R|kotlin/Int|>(Int(1))
R|<local>/passIt<CS errors: <local>/passIt>#|<<ERROR TYPE REF: Cannot infer argument for type parameter T>>.R|SubstitutionOverride<kotlin/Function1.invoke: <ERROR TYPE REF: Symbol not found for T>>|(Int(1))
}
@@ -0,0 +1,5 @@
fun main(args: Array<String>) {
val <!LOCAL_VARIABLE_WITH_TYPE_PARAMETERS!><T><!> passIt = { <!COMPONENT_FUNCTION_MISSING, VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION!>(t: <!UNRESOLVED_REFERENCE!>T<!>)<!> -> t }
<!INAPPLICABLE_CANDIDATE, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>passIt<!><Int>(1)
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>passIt<!>(1)
}
@@ -3847,6 +3847,12 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi
runTest("compiler/fir/analysis-tests/testData/resolve/problems/incompleteWhen.kt");
}
@Test
@TestMetadata("incorrectGenericLambdaProperty.kt")
public void testIncorrectGenericLambdaProperty() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt");
}
@Test
@TestMetadata("innerClassHierarchy.kt")
public void testInnerClassHierarchy() throws Exception {
@@ -3847,6 +3847,12 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest
runTest("compiler/fir/analysis-tests/testData/resolve/problems/incompleteWhen.kt");
}
@Test
@TestMetadata("incorrectGenericLambdaProperty.kt")
public void testIncorrectGenericLambdaProperty() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/problems/incorrectGenericLambdaProperty.kt");
}
@Test
@TestMetadata("innerClassHierarchy.kt")
public void testInnerClassHierarchy() throws Exception {
@@ -304,8 +304,9 @@ private fun BodyResolveComponents.createExplicitReceiverForInvokeByCallable(
symbol: FirCallableSymbol<*>
): FirExpression {
return FirPropertyAccessExpressionBuilder().apply {
val fakeSource = info.fakeSourceForImplicitInvokeCallReceiver
calleeReference = FirNamedReferenceWithCandidate(
null,
fakeSource,
symbol.callableId.callableName,
candidate
)
@@ -321,7 +322,7 @@ private fun BodyResolveComponents.createExplicitReceiverForInvokeByCallable(
if (candidate.currentApplicability == CandidateApplicability.K2_PROPERTY_AS_OPERATOR) {
nonFatalDiagnostics.add(ConePropertyAsOperator(candidate.symbol as FirPropertySymbol))
}
source = info.fakeSourceForImplicitInvokeCallReceiver
source = fakeSource
}.build().let {
callCompleter.completeCall(it, ResolutionMode.ReceiverResolution)
}.let {