[FIR] Support for EXPOSED_FUNCTION_RETURN_TYPE
This commit is contained in:
committed by
Mikhail Glukhikh
parent
0f16c88dd2
commit
4e577caa99
+18
@@ -19,6 +19,7 @@ object FirExposedVisibilityChecker : FirDeclarationChecker<FirMemberDeclaration>
|
||||
when (declaration) {
|
||||
is FirTypeAlias -> checkTypeAlias(declaration, context, reporter)
|
||||
is FirProperty -> checkProperty(declaration, context, reporter)
|
||||
is FirFunction<*> -> checkFunction(declaration, context, reporter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +32,17 @@ object FirExposedVisibilityChecker : FirDeclarationChecker<FirMemberDeclaration>
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkFunction(declaration: FirFunction<*>, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val functionVisibility = (declaration as FirMemberDeclaration).effectiveVisibility
|
||||
if (declaration !is FirConstructor) {
|
||||
val restricting = declaration.returnTypeRef.coneTypeSafe<ConeClassLikeType>()
|
||||
?.leastPermissiveDescriptor(declaration.session, functionVisibility)
|
||||
if (restricting != null) {
|
||||
reporter.reportExposure(Error.EXPOSED_FUNCTION_RETURN_TYPE, declaration.source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkProperty(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val propertyVisibility = declaration.effectiveVisibility
|
||||
val restricting =
|
||||
@@ -58,6 +70,7 @@ object FirExposedVisibilityChecker : FirDeclarationChecker<FirMemberDeclaration>
|
||||
EXPOSED_TYPEALIAS_EXPANDED_TYPE,
|
||||
EXPOSED_PROPERTY_TYPE,
|
||||
EXPOSED_RECEIVER_TYPE,
|
||||
EXPOSED_FUNCTION_RETURN_TYPE
|
||||
}
|
||||
|
||||
private fun DiagnosticReporter.reportExposure(
|
||||
@@ -80,6 +93,11 @@ object FirExposedVisibilityChecker : FirDeclarationChecker<FirMemberDeclaration>
|
||||
report(Errors.FIR_EXPOSED_RECEIVER_TYPE.onSource(it))
|
||||
}
|
||||
}
|
||||
Error.EXPOSED_FUNCTION_RETURN_TYPE -> {
|
||||
source?.let {
|
||||
report(Errors.FIR_EXPOSED_FUNCTION_RETURN_TYPE.onSource(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user