otp icon indicating copy to clipboard operation
otp copied to clipboard

Update and uniformise lists specs

Open VLanvin opened this issue 6 months ago • 3 comments

Uniformise specs to adhere to the proposed EEP 71.

Many specs use when constraints and :: inconsistenly, making it hard for type-checkers to reason about.

For example,

-spec reverse(List1) -> List2 when
      List1 :: [T],
      List2 :: [T],
      T :: term().

in this spec, List1 and List2 are arguably defined as aliases for [T], while T is defined to be "a subtype of" term().

Removing the last constraint makes it clearer that the returned list has the same type as the input list:

-spec reverse(List1) -> List2 when
      List1 :: [T],
      List2 :: [T].

This PR unifies all specs of the lists module under this principle, while minimising the amount of changes to specs: it keeps the spirit of using aliases and when constraints instead of inlining types.

VLanvin avatar Aug 20 '24 10:08 VLanvin