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.
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
// KT-2948 Assertion fails on a local enum
|
||||
|
||||
fun foo(): String {
|
||||
enum class E {
|
||||
OK
|
||||
}
|
||||
|
||||
return E.OK.toString()
|
||||
}
|
||||
|
||||
fun box(): String = foo()
|
||||
@@ -1,8 +0,0 @@
|
||||
fun box(): String {
|
||||
enum class K {
|
||||
O
|
||||
K
|
||||
}
|
||||
|
||||
return K.O.toString() + K.K.toString()
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fun box(): String {
|
||||
enum class K {
|
||||
O
|
||||
K
|
||||
}
|
||||
|
||||
return K.O.toString() + K.K.toString()
|
||||
}
|
||||
@@ -6,11 +6,11 @@ class A {
|
||||
open fun s() : String = "O"
|
||||
}
|
||||
|
||||
object O: B() {
|
||||
val o = object : B() {
|
||||
override fun s(): String = "K"
|
||||
}
|
||||
|
||||
a = B().s() + O.s()
|
||||
a = B().s() + o.s()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ class A(
|
||||
open fun s() : String = "O"
|
||||
}
|
||||
|
||||
object O: B() {
|
||||
val o = object : B() {
|
||||
override fun s(): String = "K"
|
||||
}
|
||||
|
||||
B().s() + O.s()
|
||||
B().s() + o.s()
|
||||
}()
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
fun box(): String {
|
||||
object K {
|
||||
val k = object {
|
||||
val ok = "OK"
|
||||
}
|
||||
|
||||
return K.ok
|
||||
return k.ok
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
var boo = "OK"
|
||||
var foo = object {
|
||||
val bar = object {
|
||||
val baz = boo
|
||||
}
|
||||
}
|
||||
|
||||
return foo.bar.baz
|
||||
}
|
||||
Reference in New Issue
Block a user