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

Roundtrip failure for [AsArray [Int]] #23

Closed
DavidEichmann opened this issue Sep 22, 2021 · 7 comments
Closed

Roundtrip failure for [AsArray [Int]] #23

DavidEichmann opened this issue Sep 22, 2021 · 7 comments

Comments

@DavidEichmann
Copy link

DavidEichmann commented Sep 22, 2021

This property fails: unflat @[AsArray [Int]] (flat (x :: [AsArray [Int]])) == Right x. I expect it to be true. here is a unit test case: x = [AsArray [1..3], AsArray [4..8]]

@DavidEichmann
Copy link
Author

Note that the property holds when using AsList instead of AsArray

@tittoassini
Copy link
Collaborator

tittoassini commented Oct 13, 2021

Hi David, apologies for the delay in answering your query.

The code as stated won't compile as x is not an [AsArray [Int]].

On the contrary:

unflat @[AsArray [Int]] (flat x )

will compile and fail, as it is to be expected as the serialisation of a AsList is different from that of AsArray.

Maybe I am missing the point?

@DavidEichmann
Copy link
Author

DavidEichmann commented Oct 25, 2021

@tittoassini Sorry about that, just a typo. I've updated my comment. It should have been x = [AsArray [1..3], AsArray [4..8]]. So:

λ> x = [AsArray [1..3], AsArray [4..8]]
λ> unflat @[AsArray [Int]] (flat (x :: [AsArray [Int]])) == Right x
False

When I was expecting True.

@tittoassini
Copy link
Collaborator

tittoassini commented Oct 29, 2021 via email

@bezirg
Copy link
Contributor

bezirg commented Mar 29, 2022

Hoping it would further help to catch the bug:
When using Int, it returns:

> tst $ [AsArray [(1::Int)..3], AsArray [4..8]]
(False,99,[129,1,2,3,0,65,2,2,131,3,132,0,0])

When using Word8, it returns:

> tst $ [AsArray [(1::Word8)..3], AsArray [4..8]]
(False,99,*** Exception: src/Flat/Bits.hs:50:7-72: Non-exhaustive patterns in Right (PostAligned _ f)

Also, both for int and word8:

> tst $ [AsArray [(1::Int)..3]]
(False,42,*** Exception: src/Flat/Bits.hs:50:7-72: Non-exhaustive patterns in Right (PostAligned _ f)

@tittoassini
Copy link
Collaborator

Thanks for your help and apologies for the monstrous delay in addressing this issue.

It should now be sorted (in github and soon in the 0.5 release).

It was due to a caching issue that occasionally caused the number of array elements to be overwritten incorrectly.

@DavidEichmann
Copy link
Author

Thanks for sorting this, @tittoassini! 🥳

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

No branches or pull requests

3 participants