Prohibit protected method calls from inline function

#KT-21178 Fixed
This commit is contained in:
Mikhael Bogdanov
2019-11-29 13:27:57 +01:00
parent 8383274144
commit df96841c9d
11 changed files with 225 additions and 14 deletions
@@ -0,0 +1,102 @@
// !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(<!UNUSED_PARAMETER!>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() {
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>test<!>()
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>z<!>
zVar
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>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() {
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>bind<!>()
}
}
internal class AInternal {
protected fun test() {}
protected val z: String = "1"
public var zVar: String = "1"
protected set(<!UNUSED_PARAMETER!>value<!>) {}
inline fun call() {
test()
}
@PublishedApi
internal inline fun call2() {
test()
}
}
private class X {
public class Z : A() {
public inline fun effictivelyNonPublic() {
test()
}
}
}