You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What operating system are you using, and which version?
NixOS
Describe what the problem is?
When I have the following definition
pub type Redeemer {
First(Int),
Second
}
and I attempt to pattern match on it like so
when redeemer is {
First(..) -> todo
Second -> todo
}
I get the following confusing error message
aiken::check::arity::pattern (link)
× While trying to make sense of your code...
╰─▶ I saw a pattern on a constructor that has 1 field(s) be matched with 0 argument(s).
╭─[/home/pi/proj/example.ak:21:1]
21 │ )
22 │ First(..) ->
· ──────┬─────
· ╰── Try instead: First(..)
23 │ dict.has_key(
╰────
help: When pattern-matching on constructors, you must either match the exact number of fields, or use the spread operator '..'. Note that unused fields must be discarded by prefixing their name with '_'.
Here are the things that are confusing about this:
I saw a pattern on a constructor that has 1 field(s); based on a discussion with @rvcas, my understanding is that "constructor that has 1 field(s)" would be something defined with First { field: Int }, so it's odd that it's referring to a constructor with 1 field here.
be matched with 0 argument(s). I don't believe this to be true, considering I'm using the spread operator
Try instead: First(..) it suggests that I use the exact same code that I have written
Note that even doing
First { .. } ->
Doesn't seem to work, and gives a similar error message (but with Try instead: First { .. }, for bonus points!)
What should be the expected behavior?
First, I would expect to be able to use the spread operator to ignore () style arguments as well, instead of being forced to _name, _each, _one.
Second, if that's not possible, I would expect the error message to be something like:
aiken::check::arity::pattern (link)
× While trying to make sense of your code...
╰─▶ I saw a pattern on a constructor that has 1 argument(s) (defined positionally, between parentheses) be matched with a spread operator.
╭─[/home/pi/proj/example.ak:21:1]
21 │ )
22 │ First(..) ->
· ──────┬─────
· ╰── Try instead: First(_) ->
23 │ dict.has_key(
╰────
help: When pattern-matching on constructors with positional arguments, you cannot use the spread operator.
or something similar.
The text was updated successfully, but these errors were encountered:
As an initial first improvement we can make the error message more clear and probably allow the spread for none labeled constructors. Eventually I want to just have these two different forms be captured as two different AST nodes allowing for more fine grained error messages.
What Git revision are you using?
What operating system are you using, and which version?
NixOS
Describe what the problem is?
When I have the following definition
and I attempt to pattern match on it like so
I get the following confusing error message
Here are the things that are confusing about this:
I saw a pattern on a constructor that has 1 field(s)
; based on a discussion with @rvcas, my understanding is that "constructor that has 1 field(s)" would be something defined withFirst { field: Int }
, so it's odd that it's referring to a constructor with 1 field here.be matched with 0 argument(s).
I don't believe this to be true, considering I'm using the spread operatorTry instead: First(..)
it suggests that I use the exact same code that I have writtenNote that even doing
Doesn't seem to work, and gives a similar error message (but with
Try instead: First { .. }
, for bonus points!)What should be the expected behavior?
First, I would expect to be able to use the spread operator to ignore
()
style arguments as well, instead of being forced to_name, _each, _one
.Second, if that's not possible, I would expect the error message to be something like:
or something similar.
The text was updated successfully, but these errors were encountered: