Skip to content

Commit a09dfda

Browse files
track bindings in match case
1 parent a644032 commit a09dfda

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

parser-typechecker/src/Unison/Syntax/TermPrinter.hs

+11-9
Original file line numberDiff line numberDiff line change
@@ -817,17 +817,18 @@ arity1Branches bs = [([pat], guard, body) | MatchCase pat guard body <- bs]
817817
groupCases ::
818818
(Ord v) =>
819819
[MatchCase' () (Term3 v ann)] ->
820-
[([Pattern ()], [v], [(Maybe (Term3 v ann), Term3 v ann)])]
821-
groupCases = go0
820+
[([Pattern ()], [v], [(Maybe (Term3 v ann), ([v], Term3 v ann))])]
821+
groupCases = \cases
822+
[] -> []
823+
ms@((p1, _, AbsN' vs1 _) : _) -> go (p1, vs1) [] ms
822824
where
823-
go0 [] = []
824-
go0 ms@((p1, _, AbsN' vs1 _) : _) = go2 (p1, vs1) [] ms
825-
go2 (p0, vs0) acc [] = [(p0, vs0, reverse acc)]
826-
go2 (p0, vs0) acc ms@((p1, g1, AbsN' vs body) : tl)
827-
| p0 == p1 && vs == vs0 = go2 (p0, vs0) ((g1, body) : acc) tl
828-
| otherwise = (p0, vs0, reverse acc) : go0 ms
825+
go (p0, vs0) acc [] = [(p0, vs0, reverse acc)]
826+
go (p0, vs0) acc ms@((p1, g1, AbsN' vs body) : tl)
827+
| p0 == p1 && vs == vs0 = go (p0, vs0) ((g1, (vs, body)) : acc) tl
828+
| otherwise = (p0, vs0, reverse acc) : groupCases ms
829829

830830
printCase ::
831+
forall m v.
831832
(MonadPretty v m) =>
832833
Imports ->
833834
DocLiteralContext ->
@@ -867,6 +868,7 @@ printCase im doc ms =
867868
justified
868869
justified = PP.leftJustify $ fmap (\(g, b) -> (g, (arrow, b))) gbs
869870
grid = traverse go (groupCases ms)
871+
patLhs :: PrettyPrintEnv -> [v] -> [Pattern ()] -> Pretty SyntaxText
870872
patLhs ppe vs = \cases
871873
[pat] -> PP.group (fst (prettyPattern ppe (ac Annotation Block im doc) Bottom vs pat))
872874
pats -> PP.group
@@ -899,7 +901,7 @@ printCase im doc ms =
899901
-- like any other variable, ex: case Foo x y | x < y -> ...
900902
PP.spaceIfNeeded (fmt S.DelimiterChar "|")
901903
<$> pretty0 (ac Control Normal im doc) g
902-
printBody = pretty0 (ac Annotation Block im doc)
904+
printBody (vs, body) = withBoundTerms vs (pretty0 (ac Annotation Block im doc) body)
903905

904906
-- A pretty term binding, split into the type signature (possibly empty) and the term.
905907
data PrettyBinding = PrettyBinding

unison-src/transcripts/idempotent/fix-5525.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ scratch/main> view foo
9696
foo =
9797
use Nat +
9898
bar = match 5 with
99-
1 -> 2
100-
bar1 -> bar + .bar
99+
1 -> 2
100+
bar -> bar + .bar
101101
bar
102102
```
103103

0 commit comments

Comments
 (0)