[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(
|
private fun ConeKotlinType.findVisibilityExposure(
|
||||||
context: CheckerContext,
|
context: CheckerContext,
|
||||||
base: EffectiveVisibility
|
base: EffectiveVisibility,
|
||||||
|
visitedTypes: MutableSet<ConeKotlinType> = mutableSetOf(),
|
||||||
): Pair<FirBasedSymbol<*>, EffectiveVisibility>? {
|
): 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 classSymbol = type.fullyExpandedType(context.session).lookupTag.toSymbol(context.session) ?: return null
|
||||||
|
|
||||||
val effectiveVisibility = when (classSymbol) {
|
val effectiveVisibility = when (classSymbol) {
|
||||||
@@ -239,9 +247,14 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (it in type.typeArguments) {
|
for ((index, it) in type.typeArguments.withIndex()) {
|
||||||
(it as? ConeClassLikeType)?.findVisibilityExposure(context, base)?.let {
|
when (it) {
|
||||||
return 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
|
// Ok: internal vs package-private in same package
|
||||||
internal fun internal() = My.foo()
|
internal fun internal() = My.foo()
|
||||||
// Error: protected vs package-private
|
// Error: protected vs package-private
|
||||||
protected fun protected() = My.foo()
|
protected fun <!EXPOSED_FUNCTION_RETURN_TYPE!>protected<!>() = My.foo()
|
||||||
// Error: public vs package-private
|
// Error: public vs package-private
|
||||||
fun public() = My.foo()
|
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>public<!>() = My.foo()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE: other/Your.kt
|
// FILE: other/Your.kt
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ interface Generic<E: <!EXPOSED_TYPE_PARAMETER_BOUND!>My<!>>
|
|||||||
|
|
||||||
interface Our {
|
interface Our {
|
||||||
// invalid, Generic<My> is effectively internal
|
// invalid, Generic<My> is effectively internal
|
||||||
fun foo(): Generic<*>
|
fun <!EXPOSED_FUNCTION_RETURN_TYPE!>foo<!>(): Generic<*>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user