hylo-lang / hylo

The Hylo programming language
https://www.hylo-lang.org
Apache License 2.0
1.22k stars 56 forks source link

Comparable constraint doesn't make >= operator available #1370

Open dabrahams opened 7 months ago

dabrahams commented 7 months ago

At 58b62b6adaaaa run DriverTests and you can see failures in the standard library reflecting the bug in the title.

Test Case '-[DriverTests.DriverTests testTypeCheckSuccess]' started./Users/dave/src/hylo/Tests/DriverTests/DriverTests.swift:104: error: -[DriverTests.DriverTests testTypeCheckSuccess] : XCTAssertTrue failed
/Users/dave/src/hylo/Tests/DriverTests/DriverTests.swift:105: error: -[DriverTests.DriverTests testTypeCheckSuccess] : XCTAssertEqual failed: ("
/Users/dave/src/hylo/StandardLibrary/Sources/Core/Range.hylo:27.24-26: error: type 'Bound' has no member 'infix>='
    return (e.unsafe[] >= lower_bound) && (e.unsafe[] < upper_bound)
                       ~~
/Users/dave/src/hylo/StandardLibrary/Sources/Core/Range.hylo:27.55-56: error: type 'Bound' has no member 'infix<'
    return (e.unsafe[] >= lower_bound) && (e.unsafe[] < upper_bound)
                                                      ^
/Users/dave/src/hylo/StandardLibrary/Sources/Core/Range.hylo:31.64-69: error: type 'B' does not conform to trait 'SemiRegular'
  public fun contains<B: Comparable where Bound == B>(_ other: Range<B>) -> Bool {
                                                               ~~~~~
/Users/dave/src/hylo/StandardLibrary/Sources/Core/Range.hylo:33.36-38: error: type 'Bound' has no member 'infix>='
    return (e.unsafe[].lower_bound >= self.lower_bound) && (e.unsafe[].upper_bound <= self.upper_bound)
                                   ~~
/Users/dave/src/hylo/StandardLibrary/Sources/Core/Range.hylo:33.84-86: error: type 'Bound' has no member 'infix<='
    return (e.unsafe[].lower_bound >= self.lower_bound) && (e.unsafe[].upper_bound <= self.upper_bound)
                                                                                   ~~
") is not equal to ("

If there's something not supported in the source code we should issue a "not supported" diagnostic.

kyouko-taiga commented 7 months ago

Reproducing the bug is more complex than the title suggests as this program works fine:

type X: Comparable, Deinitializable {
  public memberwise init
  public fun infix== (_ r: X) -> Bool { true }
  public fun infix< (_ r: X) -> Bool { false }
}

public fun main() {
  _ = X() >= X()
}

The issue is likely related to constraints on an associated type being not picked up properly.