unisonweb / unison

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

delete.term can lead to unnamed constructors #5381

Open ceedubs opened 1 month ago

ceedubs commented 1 month ago

Describe and demonstrate the bug

delete.term can be used to delete a type's constructor, resulting in an unnamed hash appearing in the type and a result in the todo list.

I think that instead it should fail letting you know that the constructor has references and for bonus points suggesting that you use delete.type on the type instead.

Input:

```unison
type MyType = MyConstructor
fresh/main> add
fresh/main> delete.term MyType.MyConstructor
fresh/main> view MyType
fresh/main> todo

Output:
type MyType = MyConstructor

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

      type MyType
fresh/main> add

  ⍟ I've added these definitions:

    type MyType

fresh/main> delete.term MyType.MyConstructor

  Done.

fresh/main> view MyType

  type MyType = #326g7u3sau#0

fresh/main> todo

  These types have some constructors with missing names.

    1. MyType

  You can use `view 1` and
  `alias.term <hash> <TypeName>.<ConstructorName>` to give names
  to each unnamed constructor.


**Environment (please complete the following information):**
 - `ucm --version` 1e4441890