Skip to content

Commit

Permalink
Merge pull request #4434 from unisonweb/fix/update-new-record
Browse files Browse the repository at this point in the history
  • Loading branch information
aryairani authored Nov 28, 2023
2 parents 16d88b2 + 5c5f8f5 commit 060b0c2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
4 changes: 2 additions & 2 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ findCtorNames names forwardCtorNames ctorCount n =
insertShortest m _ = m
m = foldl' insertShortest mempty (Foldable.toList center)
ctorCountGuess = fromMaybe (Map.size m) ctorCount
in if Map.size m == ctorCountGuess && all (isJust . flip Map.lookup m) [0 .. fromIntegral ctorCountGuess - 1]
in if Map.size m == ctorCountGuess && all (isJust . flip Map.lookup m . fromIntegral) [0 .. ctorCountGuess - 1]
then Right $ Map.elems m
else Left $ Output.UpdateIncompleteConstructorSet n m ctorCountGuess
else Left $ Output.UpdateIncompleteConstructorSet n m ctorCount

-- Used by `findCtorNames` to filter `forwardCtorNames` to a narrow range which will be searched linearly.
-- >>> incrementLastSegmentChar $ ForwardName.fromName $ Name.unsafeFromText "foo.bar.quux"
Expand Down
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/Codebase/Editor/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ data Output
| UpdateStartTypechecking
| UpdateTypecheckingFailure
| UpdateTypecheckingSuccess
| UpdateIncompleteConstructorSet Name (Map ConstructorId Name) Int
| UpdateIncompleteConstructorSet Name (Map ConstructorId Name) (Maybe Int)
| UpgradeFailure !NameSegment !NameSegment
| UpgradeSuccess !NameSegment !NameSegment

Expand Down
2 changes: 1 addition & 1 deletion unison-cli/src/Unison/CommandLine/OutputMessages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ notifyUser dir = \case
P.lines
[ P.wrap $
"I couldn't complete the update because I couldn't find"
<> fromString (show expectedCount)
<> fromString (maybe "" show expectedCount)
<> "constructor(s) for"
<> prettyName name
<> "where I expected to."
Expand Down
12 changes: 12 additions & 0 deletions unison-src/transcripts/update-type-add-new-record.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```ucm:hide
.lib> builtins.merge
```

```unison
unique type Foo = { bar : Nat }
```

```ucm
.> update
.> view Foo
```
35 changes: 35 additions & 0 deletions unison-src/transcripts/update-type-add-new-record.output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```unison
unique type Foo = { bar : Nat }
```

```ucm
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`:
unique type Foo
Foo.bar : Foo -> Nat
Foo.bar.modify : (Nat ->{g} Nat) -> Foo ->{g} Foo
Foo.bar.set : Nat -> Foo -> Foo
```
```ucm
.> update
Okay, I'm searching the branch for code that needs to be
updated...
That's done. Now I'm making sure everything typechecks...
Everything typechecks, so I'm saving the results...
Done.
.> view Foo
unique type Foo = { bar : Nat }
```

0 comments on commit 060b0c2

Please sign in to comment.