[FIR] Report missed diagnostics from FirSyntheticCallGenerator

#KT-58207 Fixed
This commit is contained in:
Kirill Rakhman
2023-04-24 16:54:50 +02:00
committed by Space Team
parent cb825f664f
commit 4afc5315ca
3 changed files with 32 additions and 19 deletions
@@ -19,6 +19,8 @@ import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.*
import org.jetbrains.kotlin.fir.expressions.impl.FirUnitExpression
import org.jetbrains.kotlin.fir.references.*
import org.jetbrains.kotlin.fir.references.builder.buildErrorNamedReference
import org.jetbrains.kotlin.fir.references.builder.buildResolvedErrorReference
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
import org.jetbrains.kotlin.fir.resolve.calls.FirPropertyWithExplicitBackingFieldResolvedNamedReference
@@ -610,3 +612,19 @@ fun createConeDiagnosticForCandidateWithError(
else -> ConeInapplicableCandidateError(applicability, candidate)
}
}
fun FirNamedReferenceWithCandidate.toErrorReference(diagnostic: ConeDiagnostic): FirNamedReference {
val calleeReference = this
return when (calleeReference.candidateSymbol) {
is FirErrorPropertySymbol, is FirErrorFunctionSymbol -> buildErrorNamedReference {
source = calleeReference.source
this.diagnostic = diagnostic
}
else -> buildResolvedErrorReference {
source = calleeReference.source
name = calleeReference.name
resolvedSymbol = calleeReference.candidateSymbol
this.diagnostic = diagnostic
}
}
}
@@ -385,22 +385,6 @@ class FirCallCompletionResultsWriterTransformer(
}
}
private fun FirNamedReferenceWithCandidate.toErrorReference(diagnostic: ConeDiagnostic): FirNamedReference {
val calleeReference = this
return when (calleeReference.candidateSymbol) {
is FirErrorPropertySymbol, is FirErrorFunctionSymbol -> buildErrorNamedReference {
source = calleeReference.source
this.diagnostic = diagnostic
}
else -> buildResolvedErrorReference {
source = calleeReference.source
name = calleeReference.name
resolvedSymbol = calleeReference.candidateSymbol
this.diagnostic = diagnostic
}
}
}
override fun transformSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: ExpectedArgumentType?): FirStatement {
return smartCastExpression.transformOriginalExpression(this, data)
}
@@ -848,4 +832,4 @@ private fun ExpectedArgumentType.getExpectedType(argument: FirElement): ConeKotl
ExpectedArgumentType.NoApproximation -> null
}
fun ConeKotlinType.toExpectedType(): ExpectedArgumentType = ExpectedArgumentType.ExpectedType(this)
fun ConeKotlinType.toExpectedType(): ExpectedArgumentType = ExpectedArgumentType.ExpectedType(this)
@@ -22,11 +22,13 @@ import org.jetbrains.kotlin.fir.expressions.builder.buildFunctionCall
import org.jetbrains.kotlin.fir.moduleData
import org.jetbrains.kotlin.fir.references.FirReference
import org.jetbrains.kotlin.fir.references.impl.FirStubReference
import org.jetbrains.kotlin.fir.references.isError
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
import org.jetbrains.kotlin.fir.resolve.calls.*
import org.jetbrains.kotlin.fir.resolve.createErrorReferenceWithExistingCandidate
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateError
import org.jetbrains.kotlin.fir.resolve.toErrorReference
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
import org.jetbrains.kotlin.fir.symbols.SyntheticCallableId
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
@@ -183,8 +185,17 @@ class FirSyntheticCallGenerator(
this.argumentList = argumentList
}
val argument = components.callCompleter.completeCall(fakeCallElement, ResolutionMode.ContextIndependent).result.argument
return argument as FirCallableReferenceAccess?
val result = components.callCompleter.completeCall(fakeCallElement, ResolutionMode.ContextIndependent).result
val completedCallableReference = result.argument as FirCallableReferenceAccess?
val callCalleeReference = result.calleeReference
if (callCalleeReference.isError()) {
(completedCallableReference?.calleeReference as? FirNamedReferenceWithCandidate)
?.toErrorReference(callCalleeReference.diagnostic)
?.let { completedCallableReference.replaceCalleeReference(it) }
}
return completedCallableReference
}
private fun generateCalleeReferenceWithCandidate(