Files
kotlin-fork/compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.kt
T
Svetlana Isakova 9d366cb896 Prohibit local objects and enum classes
#KT-5402 Fixed
  #KT-4838 Fixed

Resolve type of object inside local object as special, not supertype('Any').
Changed visibility of constructor of anonymous object to 'internal' to be able to resolve the following:
fun box(): String {
    var foo = object {
        val bar = object {
            val baz = "ok"
        }
    }
    return foo.bar.baz
}
The containing declaration of property initializers is constructor, so 'baz' was invisible inside private constructor.
2014-09-01 12:32:52 +04:00

30 lines
619 B
Kotlin

// KT-4351 Cannot resolve reference to self in init of class local to function
fun f() {
class MyClass() {
{
val <!UNUSED_VARIABLE!>x<!>: MyClass = MyClass()
}
fun member() {
val <!UNUSED_VARIABLE!>x<!>: MyClass = MyClass()
}
}
<!LOCAL_OBJECT_NOT_ALLOWED!>object MyObject<!> {
{
val <!UNUSED_VARIABLE!>obj<!>: MyObject = MyObject
}
}
val <!UNUSED_VARIABLE!>x<!>: MyClass = MyClass()
}
val closure = {
class MyClass {
{
val <!UNUSED_VARIABLE!>x<!>: MyClass = MyClass()
}
}
}