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
This definition should raise an error because there are two identical match clauses and the second one is unreachable:
julia>functionfoo(x)
@match x beginRational{Int}(num, den) =>beginprint("one"); 1endRational{Int}(num, den) =>beginprint("two"); 2endendend
foo (generic function with 1 method)
julia>foo(3//4)
one1
In fact, maybe we should consider erroring in general if there are unreachable clauses? For example, in this definition, the second clause is unreachable because the first clause matches everything, which should also probably raise an error:
This is doable, but with the way @match currently works, there will be a big performance penalty because we have to test all the patterns. This penalty could be reduced by changing the implementation to use type dispatch when possible and statically testing for overlapping patterns (which is infeasible if there are where clauses).
I think we should consider introducing different macros for the different semantics: @match_first (currently @match) runs the first matching case and @match_one matches exactly one case, reporting an error if more than one match.
I gave up on my effort to rewrite Rematch to use dispatch (in the hopes it would prove more performant, per the problems we saw when upgrading to 1.5), because i realized that it was just way too hard when allowing for full pattern matching.
I imagine it would be easier to implement with @match_one semantics, though still hard.
This definition should raise an error because there are two identical match clauses and the second one is unreachable:
In fact, maybe we should consider erroring in general if there are unreachable clauses? For example, in this definition, the second clause is unreachable because the first clause matches everything, which should also probably raise an error:
The text was updated successfully, but these errors were encountered: