nh7a
1
Hi there,
I came across an issue I've never had before, and am curious if there's a workaround, or this is an expected behavior / a known limitation of current version's.
class Foo {
func a<T>(_ val: T) -> String { return "not equatable" }
func a<T: Equatable>(_ val: T) -> String { return "equatable" }
}
class Bar: Foo {
// these work like a charm
func b<T>(_ val: T) -> String { return super.a(val) }
func b<T: Equatable>(_ val: T) -> String { return super.a(val) }
// "declaration 'a' cannot override more than one superclass declaration"
override func a<T>(_ val: T) -> String { return super.a(val) }
override func a<T: Equatable>(_ val: T) -> String { return super.a(val) }
}
let bar = Bar()
bar.b(1) // "equatable"
bar.b(Int.self) // "not equatable"
While I can call two superclass methods individually, why can't I override them separately?
2 Likes
jrose
(Jordan Rose)
2
Definitely seems like a bug! Please file at https://bugs.swift.org.
(I see why it's trying to do this: the <T> version of a is general enough to handle the whole <T: Equatable> version as well as the one it's actually trying to override. But when there's an exact match like this it shouldn't be considered a problem.)
2 Likes
nh7a
3
2 Likes