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

bugfix: don't consider shortening variables with use statements #5465

Merged
merged 2 commits into from
Nov 26, 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
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
37 changes: 37 additions & 0 deletions unison-src/transcripts/fix-5464.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
```ucm
scratch/main> builtins.merge lib.builtin
```

```unison
foo : Nat
foo =
baz = bar.baz + bar.baz
19

bar.baz : Nat
bar.baz = 20

qux : Nat
qux = foo + foo
```

```ucm
scratch/main> add
```

```unison
foo : Nat
foo =
baz = bar.baz + bar.baz
20

bar.baz : Nat
bar.baz = 20
```

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
```
86 changes: 86 additions & 0 deletions unison-src/transcripts/fix-5464.output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
``` ucm
scratch/main> builtins.merge lib.builtin

Done.

```
``` unison
foo : Nat
foo =
baz = bar.baz + bar.baz
19

bar.baz : Nat
bar.baz = 20

qux : Nat
qux = foo + foo
```

``` ucm

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`:

bar.baz : Nat
foo : Nat
qux : Nat

```
``` ucm
scratch/main> add

⍟ I've added these definitions:

bar.baz : Nat
foo : Nat
qux : Nat

```
``` unison
foo : Nat
foo =
baz = bar.baz + bar.baz
20

bar.baz : Nat
bar.baz = 20
```

``` ucm

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:

⊡ Previously added definitions will be ignored: bar.baz

⍟ These names already exist. You can `update` them to your
new definition:

foo : Nat

```
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

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.

```
Loading