[FIR] Support flexible types and star projections in exposed visibility declaration checker
#KT-62925
This commit is contained in:
committed by
Space Team
parent
bf86afc867
commit
a836e6bf29
+18
-5
@@ -218,9 +218,17 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
|
||||
private fun ConeKotlinType.findVisibilityExposure(
|
||||
context: CheckerContext,
|
||||
base: EffectiveVisibility
|
||||
base: EffectiveVisibility,
|
||||
visitedTypes: MutableSet<ConeKotlinType> = mutableSetOf(),
|
||||
): Pair<FirBasedSymbol<*>, EffectiveVisibility>? {
|
||||
val type = this as? ConeClassLikeType ?: return null
|
||||
if (!visitedTypes.add(this)) return null
|
||||
|
||||
val type = when (this) {
|
||||
is ConeClassLikeType -> this
|
||||
is ConeFlexibleType -> lowerBound as? ConeClassLikeType ?: return null
|
||||
else -> return null
|
||||
}
|
||||
|
||||
val classSymbol = type.fullyExpandedType(context.session).lookupTag.toSymbol(context.session) ?: return null
|
||||
|
||||
val effectiveVisibility = when (classSymbol) {
|
||||
@@ -239,9 +247,14 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
}
|
||||
}
|
||||
|
||||
for (it in type.typeArguments) {
|
||||
(it as? ConeClassLikeType)?.findVisibilityExposure(context, base)?.let {
|
||||
return it
|
||||
for ((index, it) in type.typeArguments.withIndex()) {
|
||||
when (it) {
|
||||
is ConeClassLikeType -> it.findVisibilityExposure(context, base, visitedTypes)?.let { return it }
|
||||
is ConeStarProjection -> type.toRegularClassSymbol(context.session)
|
||||
?.typeParameterSymbols?.getOrNull(index)
|
||||
?.resolvedBounds?.firstNotNullOfOrNull { it.type.findVisibilityExposure(context, base, visitedTypes) }
|
||||
?.let { return it }
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ class His {
|
||||
// Ok: internal vs package-private in same package
|
||||
internal fun internal() = My.foo()
|
||||
// Error: protected vs package-private
|
||||
protected fun protected() = My.foo()
|
||||
protected fun <!EXPOSED_FUNCTION_RETURN_TYPE!>protected<!>() = My.foo()
|
||||
// Error: public vs package-private
|
||||
fun public() = My.foo()
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>public<!>() = My.foo()
|
||||
}
|
||||
|
||||
// FILE: other/Your.kt
|
||||
|
||||
@@ -13,5 +13,5 @@ interface Generic<E: <!EXPOSED_TYPE_PARAMETER_BOUND!>My<!>>
|
||||
|
||||
interface Our {
|
||||
// invalid, Generic<My> is effectively internal
|
||||
fun foo(): Generic<*>
|
||||
}
|
||||
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>foo<!>(): Generic<*>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user