JuliaServices / Match.jl

Advanced Pattern Matching for Julia
https://juliaservices.github.io/Match.jl/latest/
Other
240 stars 22 forks source link

Error on failed match? #63

Closed jtrakk closed 1 year ago

jtrakk commented 4 years ago

Without a default match, the result is nothing.

For example, @match x begin 0 => 10; 2 => 20 end returns nothing. Usually when I forget a case, it's a bug in my code and I want an error rather than a nothing.

If I have nothing,

(1) I don't notice the problem, or (2) if I do notice the problem, the error message about unexpected Nothing appears far away from the actual bug.

Whereas if I get an error, (1) I notice the problem and (2) the error shows me where the problem is.

Would it make sense to support the safer behavior by giving an error instead of nothing?

gafter commented 1 year ago

We now do that in version 2

julia> Pkg.status()
      Status `~/.julia/environments/v1.6/Project.toml`
  [7eb4fadd] Match v2.0.0

julia> @match 1 begin
          2 => 2
       end
ERROR: MatchFailure(1)
Stacktrace:
 [1] top-level scope
   @ REPL[20]:2