[IR][tests] New test: change of visibility for callables
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
public fun publicToInternalFunction() = 42
|
||||
public fun publicToPrivateFunction() = 42
|
||||
|
||||
open class Container {
|
||||
public fun publicToProtectedFunction() = 42
|
||||
public fun publicToInternalFunction() = 42
|
||||
public fun publicToPrivateFunction() = 42
|
||||
|
||||
protected fun protectedToPublicFunction() = 42
|
||||
protected fun protectedToInternalFunction() = 42
|
||||
protected fun protectedToPrivateFunction() = 42
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
internal fun publicToInternalFunction() = 42
|
||||
private fun publicToPrivateFunction() = 42
|
||||
|
||||
open class Container {
|
||||
protected fun publicToProtectedFunction() = 42
|
||||
internal fun publicToInternalFunction() = 42
|
||||
private fun publicToPrivateFunction() = 42
|
||||
|
||||
public fun protectedToPublicFunction() = 42
|
||||
internal fun protectedToInternalFunction() = 42
|
||||
private fun protectedToPrivateFunction() = 42
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib
|
||||
STEP 1:
|
||||
dependencies: stdlib
|
||||
modifications:
|
||||
U : l1.kt.1 -> l1.kt
|
||||
@@ -0,0 +1,11 @@
|
||||
class ContainerImpl : Container() {
|
||||
// Just to check that accessing from within the class hierarchy has the same effect as accessing from the outside:
|
||||
fun publicToProtectedFunctionAccess() = publicToProtectedFunction()
|
||||
fun publicToInternalFunctionAccess() = publicToInternalFunction()
|
||||
fun publicToPrivateFunctionAccess() = publicToPrivateFunction()
|
||||
|
||||
// As far as protected members can't be accessed outside of the class hierarchy, we need special accessors.
|
||||
fun protectedToPublicFunctionAccess() = protectedToPublicFunction()
|
||||
fun protectedToInternalFunctionAccess() = protectedToInternalFunction()
|
||||
fun protectedToPrivateFunctionAccess() = protectedToPrivateFunction()
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib, lib1
|
||||
@@ -0,0 +1,127 @@
|
||||
fun test1(): String {
|
||||
return try {
|
||||
publicToInternalFunction()
|
||||
"OK"
|
||||
} catch(e: Throwable) {
|
||||
e.message.orEmpty().ifBlank { "FAIL1" }
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(): String {
|
||||
return try {
|
||||
publicToPrivateFunction()
|
||||
"FAIL2"
|
||||
} catch(e: Throwable) {
|
||||
e.checkLinkageError("function publicToPrivateFunction can not be called")
|
||||
}
|
||||
}
|
||||
|
||||
fun test3(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.publicToProtectedFunction()
|
||||
"OK"
|
||||
} catch(e: Throwable) {
|
||||
e.message.orEmpty().ifBlank { "FAIL3" }
|
||||
}
|
||||
}
|
||||
|
||||
fun test4(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.publicToInternalFunction()
|
||||
"FAIL4"
|
||||
} catch(e: Throwable) {
|
||||
e.checkLinkageError("function publicToInternalFunction can not be called")
|
||||
}
|
||||
}
|
||||
|
||||
fun test5(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.publicToPrivateFunction()
|
||||
"FAIL5"
|
||||
} catch(e: Throwable) {
|
||||
e.checkLinkageError("function publicToPrivateFunction can not be called")
|
||||
}
|
||||
}
|
||||
|
||||
fun test6(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.publicToProtectedFunctionAccess()
|
||||
"OK"
|
||||
} catch(e: Throwable) {
|
||||
e.message.orEmpty().ifBlank { "FAIL6" }
|
||||
}
|
||||
}
|
||||
|
||||
fun test7(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.publicToInternalFunctionAccess()
|
||||
"FAIL7"
|
||||
} catch(e: Throwable) {
|
||||
e.checkLinkageError("function publicToInternalFunction can not be called")
|
||||
}
|
||||
}
|
||||
|
||||
fun test8(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.publicToPrivateFunctionAccess()
|
||||
"FAIL8"
|
||||
} catch(e: Throwable) {
|
||||
e.checkLinkageError("function publicToPrivateFunction can not be called")
|
||||
}
|
||||
}
|
||||
|
||||
fun test9(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.protectedToPublicFunctionAccess()
|
||||
"OK"
|
||||
} catch(e: Throwable) {
|
||||
e.message.orEmpty().ifBlank { "FAIL9" }
|
||||
}
|
||||
}
|
||||
|
||||
fun test10(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.protectedToInternalFunctionAccess()
|
||||
"FAIL10"
|
||||
} catch(e: Throwable) {
|
||||
e.checkLinkageError("function protectedToInternalFunction can not be called")
|
||||
}
|
||||
}
|
||||
|
||||
fun test11(): String {
|
||||
val c = ContainerImpl()
|
||||
return try {
|
||||
c.protectedToPrivateFunctionAccess()
|
||||
"FAIL11"
|
||||
} catch(e: Throwable) {
|
||||
e.checkLinkageError("function protectedToPrivateFunction can not be called")
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = checkResults(test1(), test2(), test3(), test4(), test5(), test6(), test7(), test8(), test9(), test10(), test11())
|
||||
|
||||
private fun Throwable.checkLinkageError(prefix: String): String {
|
||||
if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}"
|
||||
|
||||
val expectedMessagePrefix = "$prefix because it uses unlinked symbols"
|
||||
val actualMessage = message.orEmpty()
|
||||
|
||||
return if (actualMessage.startsWith(expectedMessagePrefix))
|
||||
"OK"
|
||||
else
|
||||
"EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage"
|
||||
}
|
||||
|
||||
private fun checkResults(vararg results: String): String = when {
|
||||
results.isEmpty() -> "no results to check"
|
||||
results.all { it == "OK" } -> "OK"
|
||||
else -> results.joinToString("\n")
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
STEP 0:
|
||||
dependencies: stdlib, lib1, lib2
|
||||
@@ -0,0 +1,7 @@
|
||||
MODULES: lib1, lib2, main
|
||||
|
||||
STEP 0:
|
||||
libs: lib1, lib2, main
|
||||
|
||||
STEP 1:
|
||||
libs: lib1
|
||||
Reference in New Issue
Block a user