@@ -865,9 +865,8 @@ may check for some form of tree equivalence in a future implementation.
865865## Extra conditions: `when`, `run`
866866
867867Like an escape hatch to the structure-matching mechanism. `when=cond` requires
868- `cond`'s value be `true` for this pattern to match. `run=code` evaluates
869- `code`, usually to bind variables. For convenience, the value of `code` is
870- bound to the local `run`, which can be opted out of by quoting `run`.
868+ `cond`'s value be `true` for this pattern to match. `run=code` simply evaluates
869+ `code`, usually to bind variables or debug the matching process.
871870
872871`when` and `run` clauses may appear multiple times in any order after the
873872pattern. They are executed left-to-right, stopping if any `when=cond` evaluates
@@ -891,8 +890,8 @@ julia> JuliaLowering.@stm st begin
891890 "zero-method function $fname"
892891 [K"function" [K"call" fname args...] body] ->
893892 "normal function $fname"
894- ([K"=" [K"call" _...] _...], run= if_valid_get_args(st[1]), when= !isnothing(run )) ->
895- "deprecated call-equals form with args $run "
893+ ([K"=" [K"call" _...] _...], when=(args= if_valid_get_args(st[1]); !isnothing(args) )) ->
894+ "deprecated call-equals form with args $args "
896895 (_, run=show("printf debugging is great")) -> "something else"
897896 _ -> "something else"
898897end
@@ -923,8 +922,7 @@ function _stm(line::LineNumberNode, st, pats; debug=false)
923922 # needs to live in the first argument of :if with the extra conditions.
924923 e_check = Expr (:&& )
925924 for (ek, ev) in extras
926- push! (e_check. args, ek === :when ? ev :
927- Expr (:block , ek === :run ? :(local run = $ ev) : ev, true ))
925+ push! (e_check. args, ek === :when ? ev : Expr (:block , ev, true ))
928926 end
929927 # final arg to e_check: successful match
930928 push! (e_check. args, Expr (:block , line, :($ result_gs = $ result), true ))
@@ -1033,7 +1031,7 @@ function _stm_check_usage(pats)
10331031 if Meta. isexpr (per. args[1 ], :tuple )
10341032 @assert length (per. args[1 ]. args) >= 2 " Unnecessary tuple in $(per. args[1 ]) "
10351033 for e in per. args[1 ]. args[2 : end ]
1036- @assert (Meta. isexpr (e, :(= ), 2 ) && e. args[1 ] in (:when , :run , QuoteNode ( :run ) ),
1034+ @assert (Meta. isexpr (e, :(= ), 2 ) && e. args[1 ] in (:when , :run ),
10371035 " Expected `when=<cond>` or `run=<stmts>`, got $e " )
10381036 end
10391037 p = per. args[1 ]. args[1 ]
0 commit comments