Generate accessor for private companion object

This commit is contained in:
Dmitry Petrov
2018-06-21 17:49:21 +03:00
parent ba3411e7d7
commit d35a92a81d
23 changed files with 583 additions and 7 deletions
@@ -0,0 +1,17 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
private companion object {
val result = "OK"
}
class Nested {
fun foo() = object {
override fun toString(): String = result
}
}
fun test() = Nested().foo().toString()
}
fun box() = Outer().test()
@@ -0,0 +1,17 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
inline fun <T> run(fn: () -> T) = fn()
class Outer {
private companion object {
val result = "OK"
}
class Nested {
fun foo() = run { result }
}
fun test() = Nested().foo()
}
fun box() = Outer().test()
@@ -0,0 +1,15 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
private companion object {
val result = "OK"
}
class Nested {
fun foo() = { result }()
}
fun test() = Nested().foo()
}
fun box() = Outer().test()
@@ -0,0 +1,17 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
private companion object {
val result = "OK"
}
private inline fun bar() = result
class Nested {
fun foo(x: Outer) = x.bar()
}
fun test() = Nested().foo(this)
}
fun box() = Outer().test()
@@ -0,0 +1,15 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
private companion object {
val result = "OK"
}
class Nested {
fun foo() = result
}
fun test() = Nested().foo()
}
fun box() = Outer().test()
@@ -0,0 +1,20 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
private companion object {
fun xo() = "O"
fun xk() = "K"
}
class Nested1 {
fun foo() = xo()
}
class Nested2 {
fun bar() = xk()
}
fun test() = Nested1().foo() + Nested2().bar()
}
fun box() = Outer().test()
@@ -0,0 +1,15 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
private companion object {
override fun toString(): String = "OK"
}
class Nested {
fun foo(): Any = Outer.Companion
}
fun test() = Nested().foo().toString()
}
fun box() = Outer().test()
@@ -0,0 +1,15 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
class Outer {
protected companion object {
val result = "OK"
}
class Nested {
fun foo() = result
}
fun test() = Nested().foo()
}
fun box() = Outer().test()