Skip to content

Commit d2038b3

Browse files
committed
Use unsafe operations.
Tests fail with /Users/dave/src/hylo/Tests/LibraryTests/TestCases/RangeTests.hylo:13: precondition failure
1 parent 595b197 commit d2038b3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

StandardLibrary/Sources/Core/Range.hylo

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ public type Range<Bound: SemiRegular> {
2121
&self.upper_bound = upper_bound
2222
}
2323

24-
/// Returns `true` iff `element` is contained in `self`.
25-
public fun contains<B: Comparable where Bound == B>(_ element: B) -> Bool {
26-
((element as! Bound) >= lower_bound) && ((element as! Bound) < upper_bound)
24+
/// Returns `true` iff `x` is contained in `self`.
25+
public fun contains<B: Comparable where Bound == B>(_ x: B) -> Bool {
26+
let e = Pointer<Bound>(type_punning: pointer[to: x])
27+
return (e.unsafe[] >= lower_bound) && (e.unsafe[] < upper_bound)
2728
}
2829

2930
/// Returns `true` iff `other` is contained in `self`.
3031
public fun contains<B: Comparable where Bound == B>(_ other: Range<B>) -> Bool {
31-
((other.lower_bound as! Bound) >= self.lower_bound) && ((other.upper_bound as! Bound) <= self.upper_bound)
32+
let e = Pointer<Self>(type_punning: pointer[to: other])
33+
return (e.unsafe[].lower_bound >= self.lower_bound) && (e.unsafe[].upper_bound <= self.upper_bound)
3234
}
3335

3436
}

0 commit comments

Comments
 (0)