[FIR] Report error on non-public API access in @PublishedApi inline fun

^KT-59695: Fixed
This commit is contained in:
vladislav.grechko
2023-06-28 11:59:56 +02:00
committed by Space Team
parent 36c8987df2
commit 195ca10394
10 changed files with 14 additions and 332 deletions
@@ -47,7 +47,7 @@ object FirInlineDeclarationChecker : FirFunctionChecker() {
if (context.session.inlineCheckerExtension?.isGenerallyOk(declaration, context, reporter) == false) return
if (declaration !is FirPropertyAccessor && declaration !is FirSimpleFunction) return
val effectiveVisibility = declaration.effectiveVisibility
val effectiveVisibility = declaration.publishedApiEffectiveVisibility ?: declaration.effectiveVisibility
checkInlineFunctionBody(declaration, effectiveVisibility, context, reporter)
checkCallableDeclaration(declaration, context, reporter)
}
@@ -1,48 +0,0 @@
// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE
inline fun call(a: A) {
a.<!NON_PUBLIC_CALL_FROM_PUBLIC_INLINE!>test<!>()
<!NON_PUBLIC_CALL_FROM_PUBLIC_INLINE!>privateFun<!>()
<!NON_PUBLIC_CALL_FROM_PUBLIC_INLINE!>internalFun<!>()
}
@PublishedApi
internal inline fun callFromPublishedApi(a: A) {
a.test()
privateFun()
internalFun()
}
internal class A {
@PublishedApi
internal fun test() {
test()
privateFun()
internalFun()
}
@PublishedApi
internal fun testInline() {
test()
privateFun()
internalFun()
}
}
private fun privateFun() {
}
internal fun internalFun() {
}
@@ -1,5 +1,7 @@
// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE
// FIR_IDENTICAL
inline fun call(a: A) {
a.<!NON_PUBLIC_CALL_FROM_PUBLIC_INLINE!>test<!>()
@@ -32,10 +32,10 @@ open class A {
@PublishedApi
internal inline fun callFromPublished() {
test()
z
<!PROTECTED_CALL_FROM_PUBLIC_INLINE!>test<!>()
<!PROTECTED_CALL_FROM_PUBLIC_INLINE!>z<!>
zVar
zVar = "123"
<!PROTECTED_CALL_FROM_PUBLIC_INLINE!>zVar<!> = "123"
}
protected inline fun callFromProtected() {
@@ -67,7 +67,7 @@ class C : JavaClass() {
@PublishedApi
internal inline fun callFromPublished() {
bind()
<!PROTECTED_CALL_FROM_PUBLIC_INLINE!>bind<!>()
}
}
@@ -1,102 +0,0 @@
// !LANGUAGE: +ProhibitProtectedCallFromInline
// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE
// FILE: JavaClass.java
public abstract class JavaClass {
protected void bind() {}
}
// FILE: main.kt
open class A {
protected fun test() {}
protected val z: String = "1"
public var zVar: String = "1"
protected set(value) {}
inline fun call() {
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>test<!>()
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>z<!>
zVar
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>zVar<!> = "123"
}
internal inline fun callFromInternal() {
test()
zVar
zVar = "123"
}
@PublishedApi
internal inline fun callFromPublished() {
test()
z
zVar
zVar = "123"
}
protected inline fun callFromProtected() {
test()
zVar
zVar = "123"
}
}
class B : A() {
inline fun testB() {
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>test<!>()
}
}
class C : JavaClass() {
inline fun call() {
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>bind<!>()
}
internal inline fun callFromInternal() {
bind()
}
protected inline fun callFromProtected() {
bind()
}
@PublishedApi
internal inline fun callFromPublished() {
bind()
}
}
internal class AInternal {
protected fun test() {}
protected val z: String = "1"
public var zVar: String = "1"
protected set(value) {}
inline fun call() {
test()
}
@PublishedApi
internal inline fun call2() {
test()
}
}
private class X {
public class Z : A() {
public inline fun effictivelyNonPublic() {
test()
}
}
}
@@ -1,6 +1,8 @@
// !LANGUAGE: +ProhibitProtectedCallFromInline
// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE
// FIR_IDENTICAL
// FILE: JavaClass.java
@@ -1,175 +0,0 @@
// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE
inline fun call(a: A) {
a.test()
publishedTopLevel()
a.publishedVar
a.publishedVar = 1
publishedVarTopLevel
publishedVarTopLevel = 1
}
inline var inlineVar: Int
get() {
val a = A()
a.test()
publishedTopLevel()
a.publishedVar
a.publishedVar = 1
publishedVarTopLevel
publishedVarTopLevel = 1
return 1
}
set(value) {
val a = A()
a.test()
publishedTopLevel()
a.publishedVar
a.publishedVar = 1
publishedVarTopLevel
publishedVarTopLevel = 1
}
@PublishedApi
internal class A {
@PublishedApi
internal fun test() {
publicFun()
internalFun()
privateFun()
publicVarTopLevel
publicVarTopLevel = 1
internalVarTopLevel
internalVarTopLevel = 1
privateVarTopLevel
privateVarTopLevel = 1
publishedVar
publishedVar = 1
}
@PublishedApi
internal inline fun testInline() {
publicFun()
internalFun()
privateFun()
publicVarTopLevel
publicVarTopLevel = 1
internalVarTopLevel
internalVarTopLevel = 1
privateVarTopLevel
privateVarTopLevel = 1
publishedVar
publishedVar = 1
}
@PublishedApi
internal inline var publishedVar: Int
get() {
publicFun()
internalFun()
privateFun()
publicVarTopLevel
publicVarTopLevel = 1
internalVarTopLevel
internalVarTopLevel = 1
privateVarTopLevel
privateVarTopLevel = 1
return 1
}
set(value) {
publicFun()
internalFun()
privateFun()
publicVarTopLevel
publicVarTopLevel = 1
internalVarTopLevel
internalVarTopLevel = 1
privateVarTopLevel
privateVarTopLevel = 1
}
}
@PublishedApi
internal fun publishedTopLevel() {
publicFun()
internalFun()
privateFun()
publicVarTopLevel
publicVarTopLevel = 1
internalVarTopLevel
internalVarTopLevel = 1
privateVarTopLevel
privateVarTopLevel = 1
}
@PublishedApi
inline internal fun publishedTopLevelInline() {
publicFun()
internalFun()
privateFun()
publicVarTopLevel
publicVarTopLevel = 1
internalVarTopLevel
internalVarTopLevel = 1
privateVarTopLevel
privateVarTopLevel = 1
}
@PublishedApi
inline internal var publishedVarTopLevel: Int
get() {
publicFun()
internalFun()
privateFun()
publicVarTopLevel
publicVarTopLevel = 1
internalVarTopLevel
internalVarTopLevel = 1
privateVarTopLevel
privateVarTopLevel = 1
return 1
}
set(value) {
publicFun()
internalFun()
privateFun()
publicVarTopLevel
publicVarTopLevel = 1
internalVarTopLevel
internalVarTopLevel = 1
privateVarTopLevel
privateVarTopLevel = 1
}
fun publicFun() {}
internal fun internalFun() {}
private fun privateFun() {}
var publicVarTopLevel = 1
internal var internalVarTopLevel = 1
private var privateVarTopLevel = 1
@@ -1,4 +1,7 @@
// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE
// FIR_IDENTICAL
inline fun call(a: A) {
a.test()
publishedTopLevel()
@@ -13,7 +13,7 @@ open class AndroidTargetConfigurator :
@PublishedApi
internal inline fun inlineFunPublished(): String {
return super.classFun() + super<ModuleConfiguratorWithTests>.getConfiguratorSettings() + super<AndroidModuleConfigurator>.getConfiguratorSettings()
return <!SUPER_CALL_FROM_PUBLIC_INLINE!>super<!>.classFun() + <!SUPER_CALL_FROM_PUBLIC_INLINE!>super<ModuleConfiguratorWithTests><!>.getConfiguratorSettings() + <!SUPER_CALL_FROM_PUBLIC_INLINE!>super<AndroidModuleConfigurator><!>.getConfiguratorSettings()
}
public inline fun inlineFunAnonymousObjects(): String {
@@ -13,7 +13,7 @@ open class AndroidTargetConfigurator :
@PublishedApi
internal inline fun inlineFunPublished(): String {
return super.classFun() + super<ModuleConfiguratorWithTests>.getConfiguratorSettings() + super<AndroidModuleConfigurator>.getConfiguratorSettings()
return <!SUPER_CALL_FROM_PUBLIC_INLINE!>super<!>.classFun() + <!SUPER_CALL_FROM_PUBLIC_INLINE!>super<ModuleConfiguratorWithTests><!>.getConfiguratorSettings() + <!SUPER_CALL_FROM_PUBLIC_INLINE!>super<AndroidModuleConfigurator><!>.getConfiguratorSettings()
}
public inline fun inlineFunAnonymousObjects(): String {