Trying to compile my existing Swift code in Silver. This is the original code:
public func <(left: Time, right: Time) -> Bool {
return left.hours < right.hours || (left.hours == right.hours && left.minutes < right.minutes)
}
public func ==(left: Time, right: Time) -> Bool {
return left.hours == right.hours && left.minutes == right.minutes
}
public struct Time: Comparable {
public var hours: Int = 127
public var minutes: Int = 127
public init() {
}
public func isValid() -> Bool {
return hours != 127 && minutes != 127
}
}
If I recall correctly, the comparison functions need to be defined within the class/struct in Silver (unless that changed in the past few months). I assume this would be the Silver way, but it does not compile:
public struct Time: Comparable {
static func <(_ lhs: Time, _ rhs: Time) -> Bool {
return false
}
static func <=(_ lhs: Time, _ rhs: Time) -> Bool {
return false
}
static func >=(_ lhs: Time, _ rhs: Time) -> Bool {
return false
}
static func >(_ lhs: Time, _ rhs: Time) -> Bool {
return false
}
public var hours: Int = 127
public var minutes: Int = 127
public init() {
}
public func isValid() -> Bool {
return hours != 127 && minutes != 127
}
}
(I get the error message with the typo that was mentioned in Typo in error message)