reitzig
(Raphael R )
1
This code is illegal:
class A {
static var superA: String {
return "a"
}
}
class B : A {
func foo() {
let myA: String = superA
}
}
We need to make explicit that we're referring to a static member by writing A.superA.
Surprisingly, this compiles (Swift 4.0):
class B : A {
class Innner {
func foo() {
let myA: String = superA
}
}
}
Is this bug or feature?
Joe_Groff
(Joe Groff)
2
That looks like a bug to me.
2 Likes
reitzig
(Raphael R )
3
Should I report it, or do we need additional confirmation?
DeFrenZ
(Davide De Franceschi)
4
It seems this can be simplified to
class A {
static let superA = "a"
func foo() {
// Doesn't compile
_ = superA
// Compiles
_ = A.superA
}
class Inner {
func foo() {
// Compiles
_ = superA
}
}
}
I'm quite used to the non-compiling behaviour, as func foo works at instance-scope, and superA is defined at type scope, so that's not surprising.
I don't know if it's something that we want to revise (allowing instance scopes to access type scopes implicitly) as it might be confusing when shadowing is in place.
Though I don't understand why the instance scope of Inner should be able to access superA...
moiseev
(Max Moiseev)
5
Please report it at bugs.swift.org. This way it'll get more visibility.
reitzig
(Raphael R )
6
1 Like