[FIR] Implement RESOLUTION_TO_CLASSIFIER
This commit is contained in:
@@ -41,7 +41,7 @@ FILE: inner.kt
|
||||
public final fun test(): R|kotlin/Unit| {
|
||||
lval o: R|Owner| = R|/Owner.Owner|()
|
||||
R|<local>/o|.R|/Owner.foo|()
|
||||
lval err: <ERROR TYPE REF: Unresolved name: Inner> = Q|Owner|.<Unresolved name: Inner>#()
|
||||
lval err: <ERROR TYPE REF: Resolution to classifier> = Q|Owner|.<Resolution to classifier>#()
|
||||
R|<local>/err|.<Unresolved name: baz>#()
|
||||
lval i: R|Owner.Inner| = R|<local>/o|.R|/Owner.Inner.Inner|()
|
||||
R|<local>/i|.R|/Owner.Inner.gau|()
|
||||
|
||||
@@ -31,7 +31,7 @@ class Owner {
|
||||
fun test() {
|
||||
val o = Owner()
|
||||
o.foo()
|
||||
val err = Owner.<!UNRESOLVED_REFERENCE!>Inner<!>()
|
||||
val err = Owner.<!RESOLUTION_TO_CLASSIFIER!>Inner<!>()
|
||||
err.<!UNRESOLVED_REFERENCE!>baz<!>()
|
||||
val i = o.Inner()
|
||||
i.gau()
|
||||
|
||||
+3
@@ -124,6 +124,9 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
parameter<String>("expression")
|
||||
parameter<ConeKotlinType>("type")
|
||||
}
|
||||
val RESOLUTION_TO_CLASSIFIER by error<PsiElement> {
|
||||
parameter<FirRegularClassSymbol>("classSymbol")
|
||||
}
|
||||
}
|
||||
|
||||
val SUPER by object : DiagnosticGroup("Super") {
|
||||
|
||||
@@ -134,6 +134,7 @@ object FirErrors {
|
||||
val ILLEGAL_SELECTOR by error0<PsiElement>()
|
||||
val NO_RECEIVER_ALLOWED by error0<PsiElement>()
|
||||
val FUNCTION_EXPECTED by error2<PsiElement, String, ConeKotlinType>(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED)
|
||||
val RESOLUTION_TO_CLASSIFIER by error1<PsiElement, FirRegularClassSymbol>()
|
||||
|
||||
// Super
|
||||
val SUPER_IS_NOT_AN_EXPRESSION by error0<PsiElement>(SourceElementPositioningStrategies.REFERENCED_NAME_BY_QUALIFIED)
|
||||
|
||||
+6
@@ -329,6 +329,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REIFIED_TYPE_PARA
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REPEATED_BOUND
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REPEATED_MODIFIER
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RESERVED_MEMBER_INSIDE_INLINE_CLASS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RESOLUTION_TO_CLASSIFIER
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RESULT_TYPE_MISMATCH
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_NOT_ALLOWED
|
||||
@@ -502,6 +503,11 @@ class FirDefaultErrorMessages {
|
||||
FUNCTION_EXPECTED,
|
||||
"Expression ''{0}'' of type {1} cannot be invoked as a function. The function 'invoke()' is not found", TO_STRING, RENDER_TYPE
|
||||
)
|
||||
map.put(
|
||||
RESOLUTION_TO_CLASSIFIER,
|
||||
"Constructor of inner class {0} can be called only with receiver of containing class",
|
||||
SYMBOL
|
||||
)
|
||||
map.put(ILLEGAL_SELECTOR, "The expression cannot be a selector (occur after a dot)")
|
||||
map.put(NO_RECEIVER_ALLOWED, "No receiver can be passed to this function or property")
|
||||
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ private fun ConeDiagnostic.toFirDiagnostic(
|
||||
is ConeUnresolvedQualifierError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.qualifier)
|
||||
is ConeFunctionCallExpectedError -> FirErrors.FUNCTION_CALL_EXPECTED.createOn(source, this.name.asString(), this.hasValueParameters)
|
||||
is ConeFunctionExpectedError -> FirErrors.FUNCTION_EXPECTED.createOn(source, this.expression, this.type)
|
||||
is ConeResolutionToClassifierError -> FirErrors.RESOLUTION_TO_CLASSIFIER.createOn(source, this.classSymbol)
|
||||
is ConeHiddenCandidateError -> FirErrors.INVISIBLE_REFERENCE.createOn(source, this.candidateSymbol)
|
||||
is ConeAmbiguityError -> when {
|
||||
applicability.isSuccess -> FirErrors.OVERLOAD_RESOLUTION_AMBIGUITY.createOn(source, this.candidates.map { it.symbol })
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.*
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.tower.FirTowerResolver
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.tower.TowerResolveManager
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.symbol
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.*
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.ResolvedCallableReferenceAtom
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents
|
||||
@@ -605,15 +604,20 @@ class FirCallResolver(
|
||||
candidate?.let { isValueParametersNotEmpty(it) } ?: candidates.any { isValueParametersNotEmpty(it) })
|
||||
} else {
|
||||
val singleExpectedCandidate = expectedCandidates?.singleOrNull()
|
||||
if (singleExpectedCandidate?.symbol?.fir is FirRegularClass) {
|
||||
ConeUnresolvedNameError(name)
|
||||
// TODO: ConeResolutionToClassifierError()
|
||||
|
||||
var fir = singleExpectedCandidate?.symbol?.fir
|
||||
if (fir is FirTypeAlias) {
|
||||
fir = (fir.expandedTypeRef.coneType.fullyExpandedType(session).toSymbol(session) as? FirRegularClassSymbol)?.fir
|
||||
}
|
||||
|
||||
if (fir is FirRegularClass) {
|
||||
ConeResolutionToClassifierError(fir.symbol)
|
||||
} else {
|
||||
val coneType = explicitReceiver?.typeRef?.coneType
|
||||
if (coneType != null && !coneType.isUnit) {
|
||||
ConeFunctionExpectedError(
|
||||
name.asString(),
|
||||
(singleExpectedCandidate?.symbol?.fir as? FirTypedDeclaration)?.returnTypeRef?.coneType ?: coneType
|
||||
(fir as? FirTypedDeclaration)?.returnTypeRef?.coneType ?: coneType
|
||||
)
|
||||
} else {
|
||||
ConeUnresolvedNameError(name)
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ internal abstract class FirBaseTowerResolveTask(
|
||||
protected fun FirScope.toScopeTowerLevel(
|
||||
extensionReceiver: ReceiverValue? = null,
|
||||
extensionsOnly: Boolean = false,
|
||||
includeInnerConstructors: Boolean = true
|
||||
includeInnerConstructors: Boolean = extensionReceiver != null,
|
||||
): ScopeTowerLevel = ScopeTowerLevel(
|
||||
session, components, this,
|
||||
extensionReceiver, extensionsOnly, includeInnerConstructors
|
||||
|
||||
+4
@@ -54,6 +54,10 @@ class ConeFunctionExpectedError(val expression: String, val type: ConeKotlinType
|
||||
override val reason: String get() = "Expression '$expression' of type '$type' cannot be invoked as a function"
|
||||
}
|
||||
|
||||
class ConeResolutionToClassifierError(val classSymbol: FirRegularClassSymbol) : ConeDiagnostic() {
|
||||
override val reason: String get() = "Resolution to classifier"
|
||||
}
|
||||
|
||||
class ConeHiddenCandidateError(
|
||||
val candidateSymbol: FirBasedSymbol<*>
|
||||
) : ConeDiagnostic() {
|
||||
|
||||
Reference in New Issue
Block a user