this isn't a bug though, it's definitely expected behavior. It's just quirky. Because the case with the variable being local and having an explicit type lets you do one thing that you can't do if you don't explicitly declare the type:
open class Foo
fun test() {
var myFoo: Foo = object : Foo() {
val x = 10
}
myFoo = object : Foo() {
val y = 20
}
}