why does this not work when the struct is local to a function?
func f()
{
struct Pair:Hashable, Comparable
{
let x:Int, y:Int
static
func < (lhs:Pair, rhs:Pair) -> Bool
{
if lhs.y < rhs.y
{
return true
}
else if lhs.y == rhs.y
{
return lhs.x < rhs.x
}
else
{
return false
}
}
}
}
:3:12: error: type 'Pair' does not conform to protocol 'Comparable'
struct Pair:Hashable, Comparable
^
Certainly a bug related to operator functions in conformances. IteratorProtocol and a simple custom protocol work fine. Using a name instead of < or having a default implementation works too.
protocol P { static func < (lhs: Self, rhs: Self) -> Bool }
func f() {
struct B: P {
static func < (lhs: B, rhs: B) -> Bool {return true} // The error
}
}
1 Like
ole
(Ole Begemann)
3
This looks like the same bug as the one that's being discussed here: Hashable struct in function.
3 Likes
@Max, have you filed the bug with the Hashable struct inside a function yet?