FIR: Replace fir.bounds with resolvedBounds where it is appropriate
If there is a `coneType` call immediately after the `fir.bounds` call, it means that the fully resolved type is expected, hence `resolvedBounds` should be used
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.fir.types.isArrayType
|
||||
object FirUpperBoundsChecker : FirTypeParameterChecker() {
|
||||
|
||||
override fun check(declaration: FirTypeParameter, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (declaration.bounds.any { it.coneType.isArrayType }) {
|
||||
if (declaration.symbol.resolvedBounds.any { it.coneType.isArrayType }) {
|
||||
reporter.reportOn(declaration.source, FirJvmErrors.UPPER_BOUND_CANNOT_BE_ARRAY, context)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ object FirClassVarianceChecker : FirClassChecker() {
|
||||
) {
|
||||
for (typeParameter in typeParameters) {
|
||||
if (typeParameter is FirTypeParameter) {
|
||||
for (bound in typeParameter.bounds) {
|
||||
for (bound in typeParameter.symbol.resolvedBounds) {
|
||||
checkVarianceConflict(bound, variance, context, reporter)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.types.type
|
||||
object FirPropertyTypeParametersChecker : FirPropertyChecker() {
|
||||
|
||||
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val boundsByName = declaration.typeParameters.associate { it.name to it.bounds }
|
||||
val boundsByName = declaration.typeParameters.associate { it.name to it.symbol.resolvedBounds }
|
||||
val usedTypes = HashSet<ConeKotlinType>()
|
||||
fun collectAllTypes(type: ConeKotlinType) {
|
||||
if (usedTypes.add(type)) {
|
||||
|
||||
+4
-4
@@ -84,7 +84,7 @@ object FirTypeParameterBoundsChecker : FirTypeParameterChecker() {
|
||||
}
|
||||
|
||||
private fun checkOnlyOneTypeParameterBound(declaration: FirTypeParameter, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val bounds = declaration.bounds.distinctBy { it.coneType }
|
||||
val bounds = declaration.symbol.resolvedBounds.distinctBy { it.coneType }
|
||||
val (boundWithParam, otherBounds) = bounds.partition { it.coneType is ConeTypeParameterType }
|
||||
if (boundWithParam.size > 1 || (boundWithParam.size == 1 && otherBounds.isNotEmpty())) {
|
||||
// If there's only one problematic bound (either 2 type parameter bounds, or 1 type parameter bound + 1 other bound),
|
||||
@@ -108,7 +108,7 @@ object FirTypeParameterBoundsChecker : FirTypeParameterChecker() {
|
||||
|
||||
private fun checkBoundUniqueness(declaration: FirTypeParameter, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val seenClasses = mutableSetOf<FirRegularClassSymbol>()
|
||||
val allNonErrorBounds = declaration.bounds.filter { it !is FirErrorTypeRef }
|
||||
val allNonErrorBounds = declaration.symbol.resolvedBounds.filter { it !is FirErrorTypeRef }
|
||||
val uniqueBounds = allNonErrorBounds.distinctBy { it.coneType.classId ?: it.coneType }
|
||||
|
||||
uniqueBounds.forEach { bound ->
|
||||
@@ -140,7 +140,7 @@ object FirTypeParameterBoundsChecker : FirTypeParameterChecker() {
|
||||
return false
|
||||
}
|
||||
|
||||
if (anyConflictingTypes(declaration.bounds.map { it.coneType })) {
|
||||
if (anyConflictingTypes(declaration.symbol.resolvedBounds.map { it.coneType })) {
|
||||
reporter.reportOn(declaration.source, FirErrors.CONFLICTING_UPPER_BOUNDS, declaration.symbol, context)
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ object FirTypeParameterBoundsChecker : FirTypeParameterChecker() {
|
||||
val firTypeRefClasses = mutableListOf<Pair<FirTypeRef, FirRegularClassSymbol>>()
|
||||
val firRegularClassesSet = mutableSetOf<FirRegularClassSymbol>()
|
||||
|
||||
for (bound in declaration.bounds) {
|
||||
for (bound in declaration.symbol.resolvedBounds) {
|
||||
val classSymbol = bound.toRegularClassSymbol(context.session)
|
||||
if (firRegularClassesSet.contains(classSymbol)) {
|
||||
// no need to throw INCONSISTENT_TYPE_PARAMETER_BOUNDS diagnostics here because REPEATED_BOUNDS diagnostic is already exist
|
||||
|
||||
Reference in New Issue
Block a user