Skip to content

Instantly share code, notes, and snippets.

@gfx
Created September 14, 2014 02:13
Show Gist options
  • Save gfx/5fd30a5c496faf290f1d to your computer and use it in GitHub Desktop.
Save gfx/5fd30a5c496faf290f1d to your computer and use it in GitHub Desktop.
class Base {
init() {
println("Base")
}
}
class Derived: Base {
override init() {
super.init()
println("Derived")
}
final func f() {
println("Derived#f()")
}
func d() {
println("Derived#d()")
}
}
func make<T: Base>(t: T.Type) -> T {
return t()
}
make(Base.self) // Base
make(Derived.self) // Base
var obj = make(Derived.self) // OK but type mismatch
obj.f() // OK, static dispatch
obj.d() // EXC_BAD_ACCESS, dynamic dispatch
@Cloov
Copy link

Cloov commented Dec 11, 2014

I was suffering from this also - great find in marking as final, but it certainly does seem like a bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment