xtclang / xvm

Ecstasy and XVM
Other
201 stars 17 forks source link

Harden the List.sorted() contract #207

Closed ggleyzer closed 5 months ago

ggleyzer commented 5 months ago

While working on something, I wrote a simple test similar to this:

    Int[] ints = [3, 1, 2];
    ints.sorted(inPlace=True);
    console.print(ints);

and was quite surprised to see a non-sorted result. In a minute, I realized that our List.sorted() API contract takes the value of inPlace argument as a suggestion and not a requirement. If the List (in this case an Array) is immutable it creates a new array, sorts and returns it. I think it's wrong and it should throw.

Proposed is the corresponding API doc and implementation change