-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ordering[os.Path]
impl is broken. Trivial fix included.
#44
Comments
Do you have an failing example or test case? |
|
lihaoyi
added a commit
that referenced
this issue
Dec 10, 2021
Fixes #44 The basic issue is that our loops `i` is being incremented and fed into `getSegment` before the out-of-bounds check. Thus if two paths are identical, it ends up overshooting the end of the sequence of segments, resulting in the error reported. The fix is to order the `i += 1` such that it takes place immediately before the out-of-bounds check, to ensure it is always in bounds when we pass it to `getSegment` The `i == xSegCount` check at the bottom was also incorrect. Just because we've hit the end of the list doesn't mean the two paths are equal, as the point of the loop is to find the first non-equal string segment so we can compare them. Thus we should compare the two string segments every time: if they are equal and we haven't run out, we loop another time, otherwise we return the result of the comparison Adds a test case that reproduces the failure on master, passes on this PR Review by @lefou
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or
for { i <- 0 until xSegCount } { val cmp = x.getSegment(i) compare y.getSegment(i); if (cmp != 0) return cmp }
.EDIT: Or use the
java.lang.Comparable
ofjava.nio.file.Path
...The text was updated successfully, but these errors were encountered: