unisonweb / unison

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

Parse failure on ambiguous destructuring bind #5281

Open ceedubs opened 1 month ago

ceedubs commented 1 month ago

Describe and demonstrate the bug

Input:

```ucm
scratch/main> builtins.merge
type Foo = MyConstructor Nat

type Bar = MyConstructor Nat
scratch/main> add

The following compiles just fine:

go x =
  (Foo.MyConstructor n) = x
  n

But if MyConstructor is ambiguous, then we get a cryptic parsing error instead of a message letting us know that MyConstructor is ambiguous.

go x =
  (MyConstructor n) = x
  n

Output:
scratch/main> builtins.merge

  Done.
type Foo = MyConstructor Nat

type Bar = MyConstructor Nat

  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 Bar
      type Foo
scratch/main> add

  ⍟ I've added these definitions:

    type Bar
    type Foo

The following compiles just fine:

go x =
  (Foo.MyConstructor n) = x
  n

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

      go : Foo -> Nat

But if MyConstructor is ambiguous, then we get a cryptic parsing error instead of a message letting us know that MyConstructor is ambiguous.

go x =
  (MyConstructor n) = x
  n

  Loading changes detected in scratch.u.

  I got confused here:

      2 |   (MyConstructor n) = x

  I was surprised to find a = here.
  I was expecting one of these instead:

  * and
  * bang
  * do
  * false
  * force
  * handle
  * if
  * infixApp
  * let
  * newline or semicolon
  * or
  * quote
  * termLink
  * true
  * tuple
  * typeLink

🛑

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

I got confused here:

  2 |   (MyConstructor n) = x

I was surprised to find a = here. I was expecting one of these instead:

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):