[FIR] Report INNER_CLASS_CONSTRUCTOR_NO_RECEIVER on delegated constructor calls
#KT-59677 Fixed
This commit is contained in:
committed by
Space Team
parent
a13756cfe9
commit
72235b8527
+1
-1
@@ -1,4 +1,4 @@
|
||||
class Outer { open inner class Inner }
|
||||
fun test() {
|
||||
val x = object : <!UNRESOLVED_REFERENCE!>Outer.Inner<!>() { }
|
||||
val x = object : <!INNER_CLASS_CONSTRUCTOR_NO_RECEIVER!>Outer.Inner<!>() { }
|
||||
}
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ interface E {
|
||||
|
||||
}
|
||||
|
||||
class Test2 : A.APublicI, <!FINAL_SUPERTYPE, UNRESOLVED_REFERENCE!>B.BInner<!>() {
|
||||
class Test2 : A.APublicI, <!FINAL_SUPERTYPE, INNER_CLASS_CONSTRUCTOR_NO_RECEIVER!>B.BInner<!>() {
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class Test4 : E, A.<!INVISIBLE_REFERENCE!>AProtectedI<!> {
|
||||
|
||||
}
|
||||
|
||||
class Test5 : C.CPublicI, <!FINAL_SUPERTYPE, UNRESOLVED_REFERENCE!>B.BInner<!>() {
|
||||
class Test5 : C.CPublicI, <!FINAL_SUPERTYPE, INNER_CLASS_CONSTRUCTOR_NO_RECEIVER!>B.BInner<!>() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -400,6 +400,11 @@ private fun mapInapplicableCandidateError(
|
||||
|
||||
is AmbiguousInterceptedSymbol -> FirErrors.PLUGIN_AMBIGUOUS_INTERCEPTED_SYMBOL.createOn(source, rootCause.pluginNames)
|
||||
|
||||
is MissingInnerClassConstructorReceiver -> FirErrors.INNER_CLASS_CONSTRUCTOR_NO_RECEIVER.createOn(
|
||||
source,
|
||||
rootCause.candidateSymbol
|
||||
)
|
||||
|
||||
else -> genericDiagnostic
|
||||
}
|
||||
}.distinct()
|
||||
|
||||
+12
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.*
|
||||
import org.jetbrains.kotlin.fir.resolve.delegatingConstructorScope
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.typeContext
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
@@ -103,7 +104,7 @@ class FirTowerResolver(
|
||||
if (outerType != null)
|
||||
components.implicitReceiverStack.receiversAsReversed().drop(1).firstOrNull {
|
||||
AbstractTypeChecker.isSubtypeOf(components.session.typeContext, it.type, outerType)
|
||||
} ?: return collector // TODO: report diagnostic about not-found receiver, KT-59677
|
||||
}
|
||||
else
|
||||
null
|
||||
|
||||
@@ -120,7 +121,16 @@ class FirTowerResolver(
|
||||
scope,
|
||||
dispatchReceiver?.receiverExpression,
|
||||
givenExtensionReceiverOptions = emptyList()
|
||||
),
|
||||
).apply {
|
||||
if (outerType != null && dispatchReceiver == null) {
|
||||
val diagnostic = constructedType
|
||||
.toRegularClassSymbol(context.session)
|
||||
?.let(::MissingInnerClassConstructorReceiver)
|
||||
?: InapplicableCandidate
|
||||
|
||||
addDiagnostic(diagnostic)
|
||||
}
|
||||
},
|
||||
context
|
||||
)
|
||||
}
|
||||
|
||||
+4
-1
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.expressions.FirSmartCastExpression
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeVariable
|
||||
import org.jetbrains.kotlin.resolve.ForbiddenNamedArgumentsTarget
|
||||
@@ -166,4 +167,6 @@ class TypeVariableAsExplicitReceiver(
|
||||
|
||||
object CallToDeprecatedOverrideOfHidden : ResolutionDiagnostic(RESOLVED)
|
||||
|
||||
class AmbiguousInterceptedSymbol(val pluginNames: List<String>) : ResolutionDiagnostic(RESOLVED_WITH_ERROR)
|
||||
class AmbiguousInterceptedSymbol(val pluginNames: List<String>) : ResolutionDiagnostic(RESOLVED_WITH_ERROR)
|
||||
|
||||
class MissingInnerClassConstructorReceiver(val candidateSymbol: FirRegularClassSymbol) : ResolutionDiagnostic(INAPPLICABLE)
|
||||
Reference in New Issue
Block a user