[FIR] Move most property checks in corresponding fun in FirConstCheckVisitor
Basically moved property check code from `visitQualifiedAccessExpression` into `visitPropertyAccessExpression`
This commit is contained in:
+21
-25
@@ -209,7 +209,6 @@ private class FirConstCheckVisitor(private val session: FirSession) : FirVisitor
|
|||||||
propertyAccessExpression: FirPropertyAccessExpression, data: Nothing?
|
propertyAccessExpression: FirPropertyAccessExpression, data: Nothing?
|
||||||
): ConstantArgumentKind {
|
): ConstantArgumentKind {
|
||||||
val propertySymbol = propertyAccessExpression.toReference()?.toResolvedCallableSymbol(discardErrorReference = true)
|
val propertySymbol = propertyAccessExpression.toReference()?.toResolvedCallableSymbol(discardErrorReference = true)
|
||||||
|
|
||||||
when (propertySymbol) {
|
when (propertySymbol) {
|
||||||
null -> return ConstantArgumentKind.VALID_CONST
|
null -> return ConstantArgumentKind.VALID_CONST
|
||||||
is FirPropertySymbol -> {
|
is FirPropertySymbol -> {
|
||||||
@@ -218,8 +217,26 @@ private class FirConstCheckVisitor(private val session: FirSession) : FirVisitor
|
|||||||
return ConstantArgumentKind.ENUM_NOT_CONST
|
return ConstantArgumentKind.ENUM_NOT_CONST
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertySymbol.isConst) {
|
when {
|
||||||
return ConstantArgumentKind.VALID_CONST
|
propertySymbol.unwrapFakeOverrides().canBeEvaluated() || propertySymbol.isCompileTimeBuiltinProperty() -> {
|
||||||
|
val receiver = listOf(propertyAccessExpression.dispatchReceiver, propertyAccessExpression.extensionReceiver)
|
||||||
|
.single { it != null }
|
||||||
|
return receiver?.accept(this, data) ?: ConstantArgumentKind.VALID_CONST
|
||||||
|
}
|
||||||
|
propertySymbol.isLocal -> return ConstantArgumentKind.NOT_CONST
|
||||||
|
propertyAccessExpression.getExpandedType().classId == StandardClassIds.KClass -> return ConstantArgumentKind.NOT_KCLASS_LITERAL
|
||||||
|
propertySymbol.isConst -> return ConstantArgumentKind.VALID_CONST
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ok, because we only look at the structure, not resolution-dependent properties.
|
||||||
|
@OptIn(SymbolInternals::class)
|
||||||
|
return when (propertySymbol.fir.initializer) {
|
||||||
|
is FirConstExpression<*> -> when {
|
||||||
|
propertySymbol.isVal -> ConstantArgumentKind.NOT_CONST_VAL_IN_CONST_EXPRESSION
|
||||||
|
else -> ConstantArgumentKind.NOT_CONST
|
||||||
|
}
|
||||||
|
is FirGetClassCall -> ConstantArgumentKind.NOT_KCLASS_LITERAL
|
||||||
|
else -> ConstantArgumentKind.NOT_CONST
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is FirFieldSymbol -> {
|
is FirFieldSymbol -> {
|
||||||
@@ -271,28 +288,7 @@ private class FirConstCheckVisitor(private val session: FirSession) : FirVisitor
|
|||||||
return qualifiedAccessExpression.dispatchReceiver?.accept(this, data) ?: ConstantArgumentKind.VALID_CONST
|
return qualifiedAccessExpression.dispatchReceiver?.accept(this, data) ?: ConstantArgumentKind.VALID_CONST
|
||||||
}
|
}
|
||||||
|
|
||||||
val expressionSymbol = qualifiedAccessExpression.toReference()?.toResolvedCallableSymbol(discardErrorReference = true)
|
return ConstantArgumentKind.VALID_CONST
|
||||||
val propertySymbol = expressionSymbol as? FirPropertySymbol ?: return ConstantArgumentKind.NOT_CONST
|
|
||||||
|
|
||||||
when {
|
|
||||||
propertySymbol.unwrapFakeOverrides().canBeEvaluated() || propertySymbol.isCompileTimeBuiltinProperty() -> {
|
|
||||||
val receiver = listOf(qualifiedAccessExpression.dispatchReceiver, qualifiedAccessExpression.extensionReceiver)
|
|
||||||
.single { it != null }
|
|
||||||
return receiver?.accept(this, data) ?: ConstantArgumentKind.VALID_CONST
|
|
||||||
}
|
|
||||||
propertySymbol.isLocal -> return ConstantArgumentKind.NOT_CONST
|
|
||||||
expressionType.classId == StandardClassIds.KClass -> return ConstantArgumentKind.NOT_KCLASS_LITERAL
|
|
||||||
}
|
|
||||||
// Ok, because we only look at the structure, not resolution-dependent properties.
|
|
||||||
@OptIn(SymbolInternals::class)
|
|
||||||
return when (propertySymbol.fir.initializer) {
|
|
||||||
is FirConstExpression<*> -> when {
|
|
||||||
propertySymbol.isVal -> ConstantArgumentKind.NOT_CONST_VAL_IN_CONST_EXPRESSION
|
|
||||||
else -> ConstantArgumentKind.NOT_CONST
|
|
||||||
}
|
|
||||||
is FirGetClassCall -> ConstantArgumentKind.NOT_KCLASS_LITERAL
|
|
||||||
else -> ConstantArgumentKind.NOT_CONST
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Utils ---
|
// --- Utils ---
|
||||||
|
|||||||
Reference in New Issue
Block a user