Skip to content

better type mismatch diffing for tag unions #9329

@Anton-4

Description

@Anton-4
User := [
  LoggedIn({name: Str}),
  Guest
].{
  welcome = |self| match (self) {
    Guest => dbg "Welcome Guest"
    LoggedIn(name) => dbg "Welcome Guest".concat(name)
  }
}

main! = |_args| {
  guest : User
  guest = Guest()
  User.welcome(guest)
  guest.welcome() // ERROR

  Ok({})
}

Output:

❯ ./zig-out/bin/roc test/echo/hello.roc
-- TYPE MISMATCH ---------------------------------

The first argument being passed to this function has the wrong type:
   ┌─ /Users/username/gitrepos/roc5/roc/test/echo/hello.roc:20:3
   │
20 │   User.welcome(guest)
   │                ^^^^^

This argument has the type:

    User

But hello.User.welcome needs the first argument to be:

    [Guest, LoggedIn(Str)]

The payload type of LoggedIn is the actual problem, User has LoggedIn({ name: Str}). The error message should highlight the mismatch between LoggedIn(Str) and LoggedIn({name: Str}).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions