refi64
(Ryan Gonzalez)
1
This is particularly what I mean:
class Base {}
class Derived: Base {}
protocol Proto {
var items: Array<Base> { get }
}
extension Proto {
var items: Array<Base> {
return []
}
func show() {
print("Number of items: \(items.count)")
}
}
class Example: Proto {
let items = [Derived()]// as Array<Base>
}
let ex = Example()
ex.show()
This stumped me for a bit in one of my programs. Here, Example.items is actually Array<Derived>, so it's not overriding the Proto's default value. If I cast it to Array<Base>, then it all works.
Should this be allowed? I can't imagine how this would ever be useful...
I think this had been recently discussed at Can property shadowing warnings be improved? (re: SR-6689). @Marc_Palmer suggests that the compiler emits a warning in such case.