unison icon indicating copy to clipboard operation
unison copied to clipboard

hashes / missing names for types in both scratch file and codebase

Open ceedubs opened this issue 5 months ago • 4 comments

Describe and demonstrate the bug

When modifying a type, it is easy to end up with an error message that includes a hash and doesn't show a clear relationship to the type in the scratch file/codebase.

scratch/main> builtins.merge

  Done.
type User = User Text

User.email : User -> Text
User.email = cases User e -> e

sendEmail : Text -> User -> {IO} ()
sendEmail msg user =
  Debug.trace ("sending to " ++ email user) msg
  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 User
      User.email : User -> Text
      sendEmail  : Text -> User ->{IO} ()
scratch/main> update

  Done.
type User = User Text Nat

sendEmail : Text -> User -> {IO} ()
sendEmail msg user =
  Debug.trace ("sending to " ++ email user) msg

🛑

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

The 1st argument to `email`

          has type:  User
    but I expected:  #3otongueea

    3 | sendEmail : Text -> User -> {IO} ()
    4 | sendEmail msg user =
    5 |   Debug.trace ("sending to " ++ email user) msg

Environment (please complete the following information):

  • ucm --version 842635bbc

ceedubs avatar May 27 '25 15:05 ceedubs

I think improving the error message would be pretty simple to implement, and get us maybe 50-60% the way towards a better solution:

The 1st argument to `email`

          has type:  User
    but I expected:  User#3otongueea (shadowed by scratch.u)

    3 | sendEmail : Text -> User -> {IO} ()
    4 | sendEmail msg user =
    5 |   Debug.trace ("sending to " ++ email user) msg

mitchellwrosen avatar May 27 '25 15:05 mitchellwrosen

Maybe "(in scratch file)" and "(in branch)"; they can both have hashes too.

aryairani avatar May 27 '25 17:05 aryairani

I see, the issue is that we basically need to propagate, as if for an update, before or while we type-check, because the current type check errors are arguably out of date.

aryairani avatar May 27 '25 19:05 aryairani

We could probably speed up type-checking in general if we had a way to do it in a dependency order, and fix this issue in the process.

aryairani avatar May 27 '25 19:05 aryairani