Skip to content

Singleton emptyList is problematic #2003

Closed
@VirtuaBoza

Description

@VirtuaBoza

I just ran down a nasty bug related to this code below:

return EMPTY_LIST || (EMPTY_LIST = makeList(0, 0, SHIFT));

I did not realize that every time I was creating a new list with List(), I was getting the same instance of List. This seems counterintuitive in a library based on the idea of immutability.

Some code in the project was mutating an instance of an empty list which caused all subsequent newly minted lists to be non-empty. Obviously the code in my project was incorrect, but I came here to suggest not using a singleton pattern here regardless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions