Skip to content

Commit

Permalink
bugfix: don't consider shortening variables with use statements
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellwrosen committed Nov 25, 2024
1 parent c08c309 commit f37d844
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
1 change: 0 additions & 1 deletion parser-typechecker/src/Unison/Syntax/TermPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,6 @@ instance Monoid PrintAnnotation where

suffixCounterTerm :: (Var v) => PrettyPrintEnv -> Set Name -> Set Name -> Term2 v at ap v a -> PrintAnnotation
suffixCounterTerm n usedTm usedTy = \case
Var' v -> countHQ mempty $ HQ.unsafeFromVar v
Ref' r -> countHQ usedTm $ PrettyPrintEnv.termName n (Referent.Ref r)
Constructor' r | noImportRefs (r ^. ConstructorReference.reference_) -> mempty
Constructor' r -> countHQ usedTm $ PrettyPrintEnv.termName n (Referent.Con r CT.Data)
Expand Down
6 changes: 3 additions & 3 deletions unison-src/transcripts/fix-5464.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ bar.baz : Nat
bar.baz = 20
```

This update should succeed, but it fails because `foo` is incorrectly printed with a `use bar baz` statement, which
causes references to `bar.baz` to be captured by its locally-bound `baz`.
This update used to fail because `foo` would incorrectly print with a `use bar baz` statement, which caused references
to `bar.baz` to be captured by its locally-bound `baz`.

```ucm:error
```ucm
scratch/main> update
```
29 changes: 4 additions & 25 deletions unison-src/transcripts/fix-5464.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ bar.baz = 20
foo : Nat
```
This update should succeed, but it fails because `foo` is incorrectly printed with a `use bar baz` statement, which
causes references to `bar.baz` to be captured by its locally-bound `baz`.
This update used to fail because `foo` would incorrectly print with a `use bar baz` statement, which caused references
to `bar.baz` to be captured by its locally-bound `baz`.

``` ucm
scratch/main> update
Expand All @@ -79,29 +79,8 @@ scratch/main> update
That's done. Now I'm making sure everything typechecks...
Typechecking failed. I've updated your scratch file with the
definitions that need fixing. Once the file is compiling, try
`update` again.
Everything typechecks, so I'm saving the results...
```
``` unison :added-by-ucm scratch.u
foo : Nat
foo =
use Nat +
use bar baz
baz = baz + baz
20
bar.baz : Nat
bar.baz = 20
-- The definitions below no longer typecheck with the changes above.
-- Please fix the errors and try `update` again.
qux : Nat
qux =
use Nat +
foo + foo
Done.
```

0 comments on commit f37d844

Please sign in to comment.