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}).
Output:
The payload type of LoggedIn is the actual problem,
UserhasLoggedIn({ name: Str}). The error message should highlight the mismatch betweenLoggedIn(Str)andLoggedIn({name: Str}).