unisonweb / unison

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

Type mismatch error lacks nice message #2987

Open rlmark opened 2 years ago

rlmark commented 2 years ago

The type mismatch error for the attached sample transcript produces a non user-facing extended error message, making it difficult to understand what went wrong.

typeMismatch.md

Sorry, you hit an error we didn't make a nice message for yet.

      Here is a summary of the Note:

        simple cause:
          TypeMismatch
        context:
        Γ
          |start1|
          console.run46 : (Unit ->{Console, g9} a6) ->{IO, Exception, g9} a6
          |let-rec-marker47|
          |𝕩49|
          'Inference Ability-50
          'Inference Ability-97
          'User "g"-98
          'Inference Ability-99
          'Inference Ability-100
          'Inference Ability-101
          [...]
rlmark commented 2 years ago

I keep hitting this one. (I suspect I am the common element here), but for context and posterity this happens when you're writing ability handlers, but forget to include a reference to a generic ability in your handler.

unique ability Choice where
  choose : {Choice} Boolean
  fail : {Choice} a

first.impl : Request {g, Choice} a -> Optional a
first.impl = cases
  {pure} -> Some pure
  {Choice.fail -> resume} -> None
  {Choice.choose -> resume } ->
      result = handle resume false with first.impl
      match result with
        Some a -> Some a
        None -> handle resume true with first.impl

first : '{g, Choice} a -> Optional a -- <== this should have a {g}
first request = handle !request with first.impl

It'll give you back a note:

      Sorry, you hit an error we didn't make a nice message for yet.

      Here is a summary of the Note:

        simple cause:
          TypeMismatch
        context:
        Γ
          |start1|
          |let-rec-marker2|
          |𝕩4|
          'Inference Ability-61
          'User "g"-62
          '𝕖5 = 𝕖61, g62
          first.impl3 : Request {g, Choice} a ->{𝕖61, g62} Optional a
          |a7|
          @a8
          |g10|
          @g11
          |a13|
          @a14
          |g16|
          @g17
          |c1a3dh9i0e119|
          c1a3dh9i0e118 : Request {g17, Choice} a14
          'match-output20 = Optional a14
          'User "a"-21
          'g24 = g17
          '𝕖23 = g17
          '𝕧22 = a14
aryairani commented 4 months ago

Still happens in 0.5.23