[low level api] fix ISE: Expected FirResolvedTypeRef with ConeKotlinType but was FirImplicitTypeRefImpl for CheckDslScopeViolation
This commit is contained in:
@@ -102,6 +102,10 @@ fun FirDeclaration.hasAnnotation(classId: ClassId): Boolean {
|
|||||||
return annotations.any { it.toAnnotationClassId() == classId }
|
return annotations.any { it.toAnnotationClassId() == classId }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun FirBasedSymbol<*>.hasAnnotation(classId: ClassId): Boolean {
|
||||||
|
return resolvedAnnotationsWithClassIds.any { it.toAnnotationClassId() == classId }
|
||||||
|
}
|
||||||
|
|
||||||
fun <D> FirBasedSymbol<out D>.getAnnotationByClassId(classId: ClassId): FirAnnotation? where D : FirAnnotationContainer, D : FirDeclaration {
|
fun <D> FirBasedSymbol<out D>.getAnnotationByClassId(classId: ClassId): FirAnnotation? where D : FirAnnotationContainer, D : FirDeclaration {
|
||||||
return fir.getAnnotationByClassId(classId)
|
return fir.getAnnotationByClassId(classId)
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-10
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.*
|
|||||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||||
import org.jetbrains.kotlin.fir.matchingParameterFunctionType
|
import org.jetbrains.kotlin.fir.matchingParameterFunctionType
|
||||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.dfa.symbol
|
||||||
import org.jetbrains.kotlin.fir.resolve.directExpansionType
|
import org.jetbrains.kotlin.fir.resolve.directExpansionType
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
|
import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable
|
||||||
@@ -25,7 +26,6 @@ import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
|||||||
import org.jetbrains.kotlin.fir.scopes.FirUnstableSmartcastTypeScope
|
import org.jetbrains.kotlin.fir.scopes.FirUnstableSmartcastTypeScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
|
import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
|
||||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
import org.jetbrains.kotlin.fir.symbols.ensureResolved
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
@@ -152,7 +152,6 @@ private class ReceiverDescription(
|
|||||||
)
|
)
|
||||||
|
|
||||||
object CheckDispatchReceiver : ResolutionStage() {
|
object CheckDispatchReceiver : ResolutionStage() {
|
||||||
@OptIn(SymbolInternals::class)
|
|
||||||
override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) {
|
override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) {
|
||||||
val explicitReceiverExpression = callInfo.explicitReceiver
|
val explicitReceiverExpression = callInfo.explicitReceiver
|
||||||
if (explicitReceiverExpression.isSuperCall()) {
|
if (explicitReceiverExpression.isSuperCall()) {
|
||||||
@@ -363,7 +362,6 @@ object CheckDslScopeViolation : ResolutionStage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(SymbolInternals::class)
|
|
||||||
private fun MutableSet<ClassId>.collectDslMarkerAnnotations(context: ResolutionContext, type: ConeKotlinType) {
|
private fun MutableSet<ClassId>.collectDslMarkerAnnotations(context: ResolutionContext, type: ConeKotlinType) {
|
||||||
collectDslMarkerAnnotations(context, type.attributes.customAnnotations)
|
collectDslMarkerAnnotations(context, type.attributes.customAnnotations)
|
||||||
when (type) {
|
when (type) {
|
||||||
@@ -379,15 +377,15 @@ object CheckDslScopeViolation : ResolutionStage() {
|
|||||||
is ConeDefinitelyNotNullType -> collectDslMarkerAnnotations(context, type.original)
|
is ConeDefinitelyNotNullType -> collectDslMarkerAnnotations(context, type.original)
|
||||||
is ConeIntersectionType -> type.intersectedTypes.forEach { collectDslMarkerAnnotations(context, it) }
|
is ConeIntersectionType -> type.intersectedTypes.forEach { collectDslMarkerAnnotations(context, it) }
|
||||||
is ConeClassLikeType -> {
|
is ConeClassLikeType -> {
|
||||||
val classDeclaration = type.toSymbol(context.session)?.fir ?: return
|
val classDeclaration = type.toSymbol(context.session) ?: return
|
||||||
collectDslMarkerAnnotations(context, classDeclaration.annotations)
|
collectDslMarkerAnnotations(context, classDeclaration.resolvedAnnotationsWithClassIds)
|
||||||
when (classDeclaration) {
|
when (classDeclaration) {
|
||||||
is FirClass -> {
|
is FirClassSymbol -> {
|
||||||
for (superType in classDeclaration.superConeTypes) {
|
for (superType in classDeclaration.resolvedSuperTypes) {
|
||||||
collectDslMarkerAnnotations(context, superType)
|
collectDslMarkerAnnotations(context, superType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is FirTypeAlias -> {
|
is FirTypeAliasSymbol -> {
|
||||||
type.directExpansionType(context.session)?.let {
|
type.directExpansionType(context.session)?.let {
|
||||||
collectDslMarkerAnnotations(context, it)
|
collectDslMarkerAnnotations(context, it)
|
||||||
}
|
}
|
||||||
@@ -398,11 +396,10 @@ object CheckDslScopeViolation : ResolutionStage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(SymbolInternals::class)
|
|
||||||
private fun MutableSet<ClassId>.collectDslMarkerAnnotations(context: ResolutionContext, annotations: Collection<FirAnnotation>) {
|
private fun MutableSet<ClassId>.collectDslMarkerAnnotations(context: ResolutionContext, annotations: Collection<FirAnnotation>) {
|
||||||
for (annotation in annotations) {
|
for (annotation in annotations) {
|
||||||
val annotationClass =
|
val annotationClass =
|
||||||
annotation.annotationTypeRef.coneType.fullyExpandedType(context.session).toSymbol(context.session)?.fir as? FirClass
|
annotation.annotationTypeRef.coneType.fullyExpandedType(context.session).toSymbol(context.session) as? FirClassSymbol
|
||||||
?: continue
|
?: continue
|
||||||
if (annotationClass.hasAnnotation(dslMarkerClassId)) {
|
if (annotationClass.hasAnnotation(dslMarkerClassId)) {
|
||||||
add(annotationClass.classId)
|
add(annotationClass.classId)
|
||||||
|
|||||||
@@ -45,6 +45,12 @@ abstract class FirBasedSymbol<E : FirDeclaration> {
|
|||||||
return fir.annotations
|
return fir.annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val resolvedAnnotationsWithClassIds: List<FirAnnotation>
|
||||||
|
get() {
|
||||||
|
ensureResolved(FirResolvePhase.TYPES)
|
||||||
|
return fir.annotations
|
||||||
|
}
|
||||||
|
|
||||||
val resolvedAnnotationClassIds: List<ClassId>
|
val resolvedAnnotationClassIds: List<ClassId>
|
||||||
get() {
|
get() {
|
||||||
ensureResolved(FirResolvePhase.TYPES)
|
ensureResolved(FirResolvePhase.TYPES)
|
||||||
|
|||||||
Reference in New Issue
Block a user