Skip to content
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

bugs: list returns wrong results (likely bug in drop function) #64

Closed
emmanueltouzery opened this issue Aug 23, 2018 · 12 comments · Fixed by #65
Closed

bugs: list returns wrong results (likely bug in drop function) #64

emmanueltouzery opened this issue Aug 23, 2018 · 12 comments · Fixed by #65

Comments

@emmanueltouzery
Copy link
Contributor

noticed this in uses from my prelude.ts library :-(

list appears to get confused by a series of operations, let's say its internal structures get corrupted, and it returns wrong results.

I made a reproduction script:

const L = require("list")

let f = L.list()
for (let i=0;i<1329;i++) {
    f = L.append(i, f);
}

const b = L.drop(L.length(L.takeWhile(l=>l<=200, f)), f)
const c = L.takeWhile(l=>l<=203, b)
const d = L.drop(L.length(c), b)

console.log("FIRST ISSUE first() doesn't agree with nth(0)")
console.log(L.first(d))
console.log(L.nth(0, d))

const c1 = L.append(L.nth(0, d), c)
console.log("SECOND ISSUE list of 4 drop first and last, wrong result")
console.log(L.toArray(c1))
console.log(L.toArray(L.dropLast(1, L.drop(1, c1))))

The output is:

FIRST ISSUE first() doesn't agree with nth(0)
201
204
SECOND ISSUE list of 4 drop first and last, wrong result
[ 201, 202, 203, 204 ]
[ 201, 202 ]
@emmanueltouzery
Copy link
Contributor Author

simplified the first bug to just two drops:

const L = require("list")

let f = L.list()
for (let i=0;i<1329;i++) {
    f = L.append(i, f);
}

const xx = L.drop(3, L.drop(201, f))
console.log(L.first(xx))
console.log(L.nth(0, xx))

-- sanity check
const xx1 = L.fromArray(L.toArray(xx));
console.log(L.first(xx1))
console.log(L.nth(0, xx1))

output is =>

201
204
204
204

@emmanueltouzery emmanueltouzery changed the title bugs: list returns wrong results bugs: list returns wrong results (like bug in drop function) Aug 23, 2018
@emmanueltouzery emmanueltouzery changed the title bugs: list returns wrong results (like bug in drop function) bugs: list returns wrong results (likely bug in drop function) Aug 23, 2018
@paldepind
Copy link
Member

Thank you for reporting the issue @emmanueltouzery. I'm looking into it!

@paldepind
Copy link
Member

See #65. I've found the bug and reproduced it with a smaller test case. I'd love to get your feedback on the alternative solution I mention in the PR 😄

Thanks again for reporting the issue with a nice and simple test case 👍

@emmanueltouzery
Copy link
Contributor Author

did you check that your fix fixes both issues reproduced through the first script? The second issue from the first script may be independent because drop and dropLast use only slice. In that second issue I don't see first and last playing any role?

@paldepind
Copy link
Member

No, I missed that there were two parts and I only tested with the second code. I'll take a look at the other problem as well 😄

@emmanueltouzery
Copy link
Contributor Author

yes unfortunately there are two bugs, I ran the test script from your PR branch:

FIRST ISSUE first() doesn't agree with nth(0)
204
204
SECOND ISSUE list of 4 drop first and last, wrong result
[ 201, 202, 203, 204 ]
[ 201, 202 ]

This kind of bugs seem like showstoppers to me :-(

@emmanueltouzery
Copy link
Contributor Author

You didn't forget about other bug did you? Closing the bug makes it unclear

@paldepind
Copy link
Member

You didn't forget about other bug did you? Closing the bug makes it unclear

Don't worry, I didn't 😄

I actually didn't close the issue myself. GitHub automatically closed the issue because I merged the PR #65. Since the PR contained the text "Fixes #64" GitHub thought the issue was fixed.

This kind of bugs seem like showstoppers to me :-(

I agree. List shouldn't have any bugs. See #66. That should fix the issue.

@paldepind paldepind reopened this Sep 2, 2018
@emmanueltouzery
Copy link
Contributor Author

Yes in general in the commits i say "ref #bug" if it's related to the bug without fixing it. Great otherwise! Hope you make a bugfix release soon :-)

@paldepind
Copy link
Member

Yes in general in the commits i say "ref #bug" if it's related to the bug without fixing it.

That's a great tip!

Both issues should be fixed now so I'll close 😄

@emmanueltouzery
Copy link
Contributor Author

Sure let's close. Just lobbying for a bugfix release when possible :-)

@paldepind
Copy link
Member

Just lobbying for a bugfix release when possible :-)

I've just released a new version 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants