unisonweb / unison

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

type errors can be wrong-kinded #5440

Open ceedubs opened 2 weeks ago

ceedubs commented 2 weeks ago

Describe and demonstrate the bug

If an expression returns a value that doesn't have the same number of type parameters as the expected type, then the type error message is confusing and shows types with kind errors.

Instead of:

 I found a value  of type:  Either Text
  where I expected to find:  Optional

I would expect:

 I found a value  of type:  Either Text a
  where I expected to find:  Optional Nat

or something like that...I'm not quite sure what it should infer for the right side of the Either.

Input:

```ucm
fresh/main> builtins.merge
foo : Optional Nat
foo = Left "error"

Output:
```` markdown
``` ucm
fresh/main> builtins.merge

  Done.
foo : Optional Nat
foo = Left "error"

  Loading changes detected in scratch.u.

  I found a value  of type:  Either Text
  where I expected to find:  Optional

      1 | foo : Optional Nat
      2 | foo = Left "error"

🛑

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

I found a value of type: Either Text where I expected to find: Optional

  1 | foo : Optional Nat
  2 | foo = Left "error"


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

**Environment (please complete the following information):**
 - `ucm --version` c8f412655
aryairani commented 2 weeks ago

Yeah I ran into this too and found it confusing / unhelpful.

aryairani commented 2 weeks ago

First steps would be to just dig into it a bit and see what's going on.