KT-60092 Fix suppression logic for EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR
This commit is contained in:
committed by
Space Team
parent
a78d631b16
commit
777df2d923
+65
-46
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.correspondingProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType
|
||||
@@ -112,65 +113,83 @@ object FirExposedVisibilityDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
functionVisibility = EffectiveVisibility.PrivateInClass
|
||||
}
|
||||
|
||||
if (functionVisibility == EffectiveVisibility.Local) return
|
||||
if (declaration !is FirConstructor && declaration !is FirPropertyAccessor) {
|
||||
declaration.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, functionVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
reporter.reportOn(
|
||||
declaration.source,
|
||||
FirErrors.EXPOSED_FUNCTION_RETURN_TYPE,
|
||||
functionVisibility,
|
||||
restricting,
|
||||
restrictingVisibility,
|
||||
context
|
||||
)
|
||||
}
|
||||
}
|
||||
val isNonLocal = functionVisibility != EffectiveVisibility.Local
|
||||
|
||||
if (declaration !is FirPropertyAccessor) {
|
||||
declaration.valueParameters.forEachIndexed { i, valueParameter ->
|
||||
if (i < declaration.valueParameters.size) {
|
||||
val (restricting, restrictingVisibility) = valueParameter.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, functionVisibility) ?: return@forEachIndexed
|
||||
reporter.reportOn(
|
||||
valueParameter.source,
|
||||
FirErrors.EXPOSED_PARAMETER_TYPE,
|
||||
functionVisibility,
|
||||
restricting,
|
||||
restrictingVisibility,
|
||||
context
|
||||
)
|
||||
if (isNonLocal && declaration !is FirConstructor) {
|
||||
declaration.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, functionVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
reporter.reportOn(
|
||||
declaration.source,
|
||||
FirErrors.EXPOSED_FUNCTION_RETURN_TYPE,
|
||||
functionVisibility,
|
||||
restricting,
|
||||
restrictingVisibility,
|
||||
context
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
for (valueParameter in declaration.valueParameters) {
|
||||
var exposureFound = false
|
||||
|
||||
if (isNonLocal) {
|
||||
valueParameter.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, functionVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
reporter.reportOn(
|
||||
valueParameter.source,
|
||||
FirErrors.EXPOSED_PARAMETER_TYPE,
|
||||
functionVisibility,
|
||||
restricting,
|
||||
restrictingVisibility,
|
||||
context
|
||||
)
|
||||
exposureFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if (exposureFound) continue
|
||||
|
||||
val property = valueParameter.correspondingProperty ?: continue
|
||||
if (property.isLocal) continue
|
||||
val propertyVisibility = property.effectiveVisibility
|
||||
|
||||
if (propertyVisibility == EffectiveVisibility.Local) continue
|
||||
property.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, propertyVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
reporter.reportOn(
|
||||
valueParameter.source,
|
||||
FirErrors.EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR,
|
||||
propertyVisibility,
|
||||
restricting,
|
||||
restrictingVisibility,
|
||||
context
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
checkMemberReceiver(declaration.receiverParameter?.typeRef, declaration as? FirCallableDeclaration, reporter, context)
|
||||
|
||||
if (isNonLocal) {
|
||||
checkMemberReceiver(declaration.receiverParameter?.typeRef, declaration as? FirCallableDeclaration, reporter, context)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkProperty(declaration: FirProperty, reporter: DiagnosticReporter, context: CheckerContext) {
|
||||
if (declaration.fromPrimaryConstructor == true) return
|
||||
if (declaration.isLocal) return
|
||||
val propertyVisibility = declaration.effectiveVisibility
|
||||
|
||||
if (propertyVisibility == EffectiveVisibility.Local) return
|
||||
declaration.returnTypeRef.coneType
|
||||
.findVisibilityExposure(context, propertyVisibility)?.let { (restricting, restrictingVisibility) ->
|
||||
if (declaration.fromPrimaryConstructor == true) {
|
||||
reporter.reportOn(
|
||||
declaration.source,
|
||||
FirErrors.EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR,
|
||||
propertyVisibility,
|
||||
restricting,
|
||||
restrictingVisibility,
|
||||
context
|
||||
)
|
||||
} else {
|
||||
reporter.reportOn(
|
||||
declaration.source,
|
||||
FirErrors.EXPOSED_PROPERTY_TYPE,
|
||||
propertyVisibility,
|
||||
restricting,
|
||||
restrictingVisibility,
|
||||
context
|
||||
)
|
||||
}
|
||||
reporter.reportOn(
|
||||
declaration.source,
|
||||
FirErrors.EXPOSED_PROPERTY_TYPE,
|
||||
propertyVisibility,
|
||||
restricting,
|
||||
restrictingVisibility,
|
||||
context
|
||||
)
|
||||
}
|
||||
checkMemberReceiver(declaration.receiverParameter?.typeRef, declaration, reporter, context)
|
||||
}
|
||||
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
private enum class Foo { A, B }
|
||||
|
||||
class Bar(<!EXPOSED_PARAMETER_TYPE!>val <!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR!>foo<!>: Foo<!>)
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
private enum class Foo { A, B }
|
||||
|
||||
class Bar(<!EXPOSED_PARAMETER_TYPE!>val foo: Foo<!>)
|
||||
@@ -6,7 +6,7 @@ public interface Your: <!EXPOSED_SUPER_INTERFACE!>My<!> {
|
||||
fun <T: Base> foo(): T
|
||||
}
|
||||
|
||||
public class Derived<T: <!EXPOSED_TYPE_PARAMETER_BOUND!>My<!>>(<!EXPOSED_PARAMETER_TYPE!>val <!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR!>x<!>: My<!>): <!EXPOSED_SUPER_CLASS!>Base<!>() {
|
||||
public class Derived<T: <!EXPOSED_TYPE_PARAMETER_BOUND!>My<!>>(<!EXPOSED_PARAMETER_TYPE!>val x: My<!>): <!EXPOSED_SUPER_CLASS!>Base<!>() {
|
||||
|
||||
constructor(<!EXPOSED_PARAMETER_TYPE!>xx: My?<!>, <!EXPOSED_PARAMETER_TYPE!>x: My<!>): this(xx ?: x)
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// ISSUE: KT-45043, KT-51229
|
||||
// DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
private class Bar
|
||||
|
||||
sealed class SealedFoo(
|
||||
val <!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR!>x<!>: Bar,
|
||||
private val y: Bar,
|
||||
z: Bar
|
||||
)
|
||||
|
||||
abstract class AbstractFoo(
|
||||
<!EXPOSED_PARAMETER_TYPE!>val <!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR!>x<!>: Bar<!>,
|
||||
<!EXPOSED_PARAMETER_TYPE!>private val y: Bar<!>,
|
||||
<!EXPOSED_PARAMETER_TYPE!>z: Bar<!>
|
||||
)
|
||||
|
||||
internal sealed class A {
|
||||
protected abstract val b: B?
|
||||
protected data class B(val s: String)
|
||||
internal data class C private constructor(override val b: B?) : A() {
|
||||
constructor() : this(null)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-45043, KT-51229
|
||||
// DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
// ISSUE: KT-57458
|
||||
|
||||
private enum class Foo { A, B }
|
||||
|
||||
class Bar constructor(
|
||||
<!EXPOSED_PARAMETER_TYPE!>@Suppress("EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR")
|
||||
val <!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR!>foo<!>: Foo<!>,
|
||||
)
|
||||
|
||||
class Var constructor(
|
||||
<!EXPOSED_PARAMETER_TYPE!>@property:Suppress("EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR")
|
||||
val foo: Foo<!>,
|
||||
)
|
||||
|
||||
class Zar constructor(
|
||||
<!EXPOSED_PARAMETER_TYPE!>@param:Suppress("EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR")
|
||||
val <!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR!>foo<!>: Foo<!>,
|
||||
)
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-57458
|
||||
|
||||
private enum class Foo { A, B }
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
// ISSUE: KT-57458
|
||||
|
||||
private enum class Foo { A, B }
|
||||
|
||||
class Bar private constructor(
|
||||
@Suppress("EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR")
|
||||
val <!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR!>foo<!>: Foo,
|
||||
)
|
||||
|
||||
class Var private constructor(
|
||||
@property:Suppress("EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR")
|
||||
val foo: Foo,
|
||||
)
|
||||
|
||||
class Zar private constructor(
|
||||
@param:Suppress("EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR")
|
||||
val <!EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR!>foo<!>: Foo,
|
||||
)
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-57458
|
||||
|
||||
private enum class Foo { A, B }
|
||||
|
||||
Reference in New Issue
Block a user