unison
unison copied to clipboard
`edit` producing malformed code according to the LSP (code included)
add
RangedFloat.decoder : Optional Float -> Optional Float -> '{Decoder} Float
RangedFloat.decoder min max = do match value! with
Unparsed a -> Float.fromText a |> Optional.filter (range min max) |> cases
None -> Decoder.fail ("Expected value in range.")
Some a -> a
_ -> Decoder.fail "Expected number"
and then edit RangedFloat.decoder to get back
RangedFloat.decoder : Optional Float -> Optional Float -> '{Decoder} Float
RangedFloat.decoder min max = use Decoder fail -- <-- LSP reports "I expected a block after this (in red), but there wasn't one ...
do
match value! with
Unparsed a ->
Float.fromText a |> Optional.filter (range min max) |> (cases
None -> fail "Expected value in range."
Some a -> a)
_ -> fail "Expected number"
If I edit the edit-produced code to:
RangedFloat.decoder : Optional Float -> Optional Float -> '{Decoder} Float
RangedFloat.decoder min max = do
match value! with
Unparsed a ->
Float.fromText a |> Optional.filter (range min max) |> (cases
None -> fail "Expected value in range."
Some a -> a)
_ -> fail "Expected number"
The problem goes away.
Possibly a dupe of https://github.com/unisonweb/unison/issues/4344 but I'll leave it open.
I tried to replicate this, but had to water it down a little (range isn’t something I could find). You can see in this transcript output that use Decoder fail is no longer in the output, but I’m not sure if that means it’s fixed or if I just couldn’t match the code path you hit.
If you still manage to trigger this behavior, please add another example – or let me know if you can get my transcript to trigger it for you.
transcript output
scratch/main> lib.install @unison/json
Downloaded 14452 entities.
I installed @unison/json/releases/1.2.3 as unison_json_1_2_3.
RangedFloat.decoder : Float -> Float -> '{Decoder} Float
RangedFloat.decoder min max = do match value! with
Unparsed a -> Float.fromText a |> Optional.filter (x -> x < max) |> cases
None -> Decoder.fail ("Expected value in range.")
Some a -> a
_ -> Decoder.fail "Expected number"
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
do an `add` or `update`, here's how your codebase would
change:
⍟ These new definitions are ok to `add`:
RangedFloat.decoder : Float -> Float -> '{Decoder} Float
scratch/main> add
⍟ I've added these definitions:
RangedFloat.decoder : Float -> Float -> '{Decoder} Float
scratch/main> edit RangedFloat.decoder
☝️
I added 1 definitions to the top of scratch.u
You can edit them there, then run `update` to replace the
definitions currently in this namespace.
scratch/main> load
Loading changes detected in scratch.u.
I found and typechecked the definitions in scratch.u. This
file has been previously added to the codebase.
RangedFloat.decoder : Float -> Float -> '{Decoder} Float
RangedFloat.decoder min max = do match value! with
Unparsed a ->
Float.fromText a |> Optional.filter (x -> x Universal.< max) |> (cases
None -> Decoder.fail "Expected value in range."
Some a -> a)
_ -> Decoder.fail "Expected number"