Stream: beginners

Topic: Unexpected Results from List.prepend


view this post on Zulip Michael Pfeifer (Jan 02 2024 at 19:47):

I am seeing unexpected results from List.prepend. The following file contains three tests.

interface EIR exposes [] imports []

expect
       List.prepend [2] 1 == [1, 2]

expect
    payment1 : { amount: Dec, date: [RD I32] }
    payment1 = { amount: 1dec, date: (RD 1000) }
    payment2 : { amount: Dec, date: [RD I32] }
    payment2 = { amount: 2dec, date: (RD 1001) }
    both = [payment1, payment2]
    List.prepend [payment2] payment1 == both

expect
    payment1 : { amount: Dec, date: [RD Dec] }
    payment1 = { amount: 1dec, date: (RD 1000) }
    payment2 : { amount: Dec, date: [RD Dec] }
    payment2 = { amount: 2dec, date: (RD 1001) }
    both = [payment1, payment2]
    List.prepend [payment2] payment1 == both

The first very simple test succeeds. The second one fails. List.prepend returns something like

[{ amount: 1, date: RD 1000 }, { amount: 18465.190817783261167616, date: RD 797499858 }]

The third test succeeds. The differences between the second test and the third test are the two type annotations. I32instead of Dec.

I tried with a nightly build and with a build that I compiled by myself.

I tried to find some issue or pull request that seems to address this behavior. The only issue that looks somewhat relevant is https://github.com/roc-lang/roc/issues/6139 (Reference counting/oportunistic mutation bug (?)).

I first encountered this behavior when working with List.concat. For this case, I had a look at the Zig implementation of concat. Everything looked fine, given my limited understanding. Unfortunately, I have no idea what to do next.

Thanks for your help.

view this post on Zulip Brendan Hansknecht (Jan 02 2024 at 23:32):

Thanks for the small repro. Can you file an issue?

view this post on Zulip Michael Pfeifer (Jan 03 2024 at 20:06):

Sure. https://github.com/roc-lang/roc/issues/6343 (Unexpected Results from List.prepend).


Last updated: Jul 06 2025 at 12:14 UTC