unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.75k stars 269 forks source link

move.namespace doesn't do dependency checks #3703

Open ceedubs opened 1 year ago

ceedubs commented 1 year ago

If the destination for move.namespace is outside of the current namespace, then it is effectively a delete.namespace from the perspective of the current namespace/project. However, it doesn't do the dependency checks that delete.namespace performs.

Transcript

```ucm
.> cd myproject
.myproject> builtins.merge
foo.bar = "foo.bar"

dependsOnBar = "dependsOn: " ++ foo.bar
.myproject> add
.myproject> move.namespace foo .void
.myproject> edit dependsOnBar
.myproject> load scratch.u

# Transcript output

  ❓

    An error occurred while running the following file: move-namespace.md

    ```ucm
    .> cd myproject

      ☝️  The namespace .myproject is empty.

    .myproject> builtins.merge

      Done.
```unison
foo.bar = "foo.bar"

dependsOnBar = "dependsOn: " ++ foo.bar
```

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

      dependsOnBar : Text
      foo.bar      : Text

```
```ucm
.myproject> add

  ⍟ I've added these definitions:

    dependsOnBar : Text
    foo.bar      : Text

.myproject> move.namespace foo .void

  Done.

.myproject> edit dependsOnBar

  ☝️

  I added these definitions to the top of
  /Users/cody/code/unison/scratch.u

    dependsOnBar : Text
    dependsOnBar =
      use Text ++
      "dependsOn: " ++ bar

  You can edit them there, then do `update` to replace the
  definitions currently in this namespace.

.myproject> load scratch.u

  I couldn't find any definitions matching the name bar inside the namespace .myproject

      4 |   "dependsOn: " ++ bar

  Some common causes of this error include:
    * Your current namespace is too deep to contain the
      definition in its subtree
    * The definition is part of a library which hasn't been
      added to this project

  To add a library to this project use the command: `fork <.path.to.lib> .myproject.lib.<libname>`

  Whatever it is, its type should conform to Text.

```

🛑

The transcript failed due to an error in the stanza above. The error is:

  I couldn't find any definitions matching the name bar inside the namespace .myproject

      4 |   "dependsOn: " ++ bar

  Some common causes of this error include:
    * Your current namespace is too deep to contain the
      definition in its subtree
    * The definition is part of a library which hasn't been
      added to this project

  To add a library to this project use the command: `fork <.path.to.lib> .myproject.lib.<libname>`

  Whatever it is, its type should conform to Text.
ceedubs commented 1 year ago

It occurs to me that this could be the case for move.term and move.type as well, but I haven't checked those.