unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

Two fixes for the infix application term printer #5384

Closed runarorama closed 1 month ago

runarorama commented 1 month ago

This fixes two issues with the term printer when printing infix operator application.

  1. Actual bug: Printer would re-associate expression to the left when the expression on the right has the same precedence as the expression on the left. For example 1 - (2 - 3) would get printed as 1 - 2 - 3 which is wrong.

  2. Formatting regression: The old term printer would lay out infix operator applications in a table. This was somewhat nicer in some cases, but bad for readability in some others. This PR reverts the printer to the old version only in the case when several applications of the same operator are chained together in a left-associated expression. This renders e.g.

[1,2,3] 
   |> foo
   |> bar
   |> baz

...when space is limited, instead of e.g.

[1,2,3] |> foo |> bar
  |> baz

If the operators are associated to the right, or if multiple operators are mixed together, the printer reverts to the normal way of printing.

aryairani commented 1 month ago

@runarorama Looks like there is some interaction with rewrites in rewrites.md that is failing CI; could you take a look? Feel free to pull in whoever.