FIR checker: report non-typed LHS of callable references

This commit is contained in:
Jinseong Jeon
2021-03-04 09:44:34 -08:00
committed by Mikhail Glukhikh
parent 329be4f906
commit 33c5b49632
20 changed files with 195 additions and 39 deletions
@@ -82,6 +82,10 @@ class ConeTypeParameterSupertype(val symbol: FirTypeParameterSymbol) : ConeDiagn
override val reason: String get() = "Type parameter ${symbol.fir.name} cannot be a supertype"
}
class ConeTypeParameterInQualifiedAccess(val symbol: FirTypeParameterSymbol) : ConeDiagnostic() {
override val reason: String get() = "Type parameter ${symbol.fir.name} in qualified access"
}
private fun describeSymbol(symbol: AbstractFirBasedSymbol<*>): String {
return when (symbol) {
is FirClassLikeSymbol<*> -> symbol.classId.asString()
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.calls.*
import org.jetbrains.kotlin.fir.resolve.dfa.FirDataFlowAnalyzer
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeTypeParameterInQualifiedAccess
import org.jetbrains.kotlin.fir.resolve.inference.*
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirArrayOfCallTransformer
@@ -89,11 +90,14 @@ class FirCallCompletionResultsWriterTransformer(
// e.g. `T::toString` where T is a generic type.
// in these cases we should report an error on
// the calleeReference.source which is not a fake source.
// uncommenting `?.fakeElement...` here removes reports
// of OTHER_ERROR from tests.
buildErrorTypeRef {
source = calleeReference.source //?.fakeElement(FirFakeSourceElementKind.ImplicitTypeRef)
diagnostic = ConeSimpleDiagnostic("Callee reference to candidate without return type: ${declaration.render()}")
source = calleeReference.source?.fakeElement(FirFakeSourceElementKind.ImplicitTypeRef)
diagnostic =
when (declaration) {
is FirTypeParameter -> ConeTypeParameterInQualifiedAccess(declaration.symbol)
is FirResolvedReifiedParameterReference -> ConeTypeParameterInQualifiedAccess(declaration.symbol)
else -> ConeSimpleDiagnostic("Callee reference to candidate without return type: ${declaration.render()}")
}
}
}