Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting on handle-with blocks #4671

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions parser-typechecker/src/Unison/Syntax/TermParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,12 @@ lam p = label "lambda" $ mkLam <$> P.try (some prefixDefinitionName <* reserved
letBlock, handle, ifthen :: (Monad m, Var v) => TermP v m
letBlock = label "let" $ (snd <$> block "let")
handle = label "handle" do
(_spanAnn, b) <- block "handle"
(_spanAnn, handler) <- block "with"
pure $ Term.handle (ann b) handler b
(handleSpan, b) <- block "handle"
(_withSpan, handler) <- block "with"
-- We don't use the annotation span from 'with' here because it will
-- include a dedent if it's at the end of block.
-- Meaning the newline gets overwritten when pretty-printing and it messes things up.
pure $ Term.handle (handleSpan <> ann handler) handler b

checkCasesArities :: (Ord v, Annotated a) => NonEmpty (Int, a) -> P v m (Int, NonEmpty a)
checkCasesArities cases@((i, _) NonEmpty.:| rest) =
Expand Down
13 changes: 13 additions & 0 deletions unison-src/transcripts/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ ability Thing where
more : Nat -> Text -> Nat
doThing : Nat -> Int
{{ Ability with single constructor }}
structural ability Ask a where
ask : {Ask a} a
-- Regression test for: https://github.com/unisonweb/unison/issues/4666
provide : a -> '{Ask a} r -> r
provide a action =
h = cases
{ask -> resume} -> handle resume a with h
{r} -> r
handle !action with h
{{
A Doc before a type
}}
Expand Down
25 changes: 25 additions & 0 deletions unison-src/transcripts/formatter.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ ability Thing where
more : Nat -> Text -> Nat
doThing : Nat -> Int


{{ Ability with single constructor }}
structural ability Ask a where
ask : {Ask a} a

-- Regression test for: https://github.com/unisonweb/unison/issues/4666
provide : a -> '{Ask a} r -> r
provide a action =
h = cases
{ask -> resume} -> handle resume a with h
{r} -> r
handle !action with h

{{
A Doc before a type
}}
Expand Down Expand Up @@ -86,6 +99,18 @@ ability Thing where
more : Nat -> Text ->{Thing} Nat
doThing : Nat ->{Thing} Int


Ask.doc = {{ Ability with single constructor }}
structural ability Ask a where ask : {Ask a} a

-- Regression test for: https://github.com/unisonweb/unison/issues/4666
provide : a -> '{Ask a} r -> r
provide a action =
h = cases
{ ask -> resume } -> handle resume a with h
{ r } -> r
handle !action with h

Optional.doc = {{ A Doc before a type }}
structural type Optional a = More Text | Some | Other a | None Nat

Expand Down
Loading