Skip to content

Puzzling behaviour of List.Buffer.toList() #195

Description

@hencjo

It seems List.Buffer.snoc (and friends) are meant only to be used through chained calls with a final call to toList(). However, it is possible and sometimes useful to call toList() more than once. In those cases it seem to be returning bogus:

Affects FJ 4.4.

enum Uni {UNI}

@Test
public void test_List_Buffer_snoc() {
    List.Buffer<Uni> lb0 = List.Buffer.<Uni>empty();

    List.Buffer<Uni> lb1 = lb0.snoc(Uni.UNI);
    List<Uni> ls1 = lb1.toList();
    assertEquals(1, ls1.length()); //As expected, ls1.length() == 1

    List.Buffer<Uni> lb2 = lb1.snoc(Uni.UNI);
    List<Uni> ls2 = lb2.toList();

    assertEquals(1, ls1.length()); // But, ls1.length() == 3 !
    assertEquals(2, ls2.length()); // Also, ls2.length() == 0 !
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions