File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed
Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -44,17 +44,18 @@ def getMatchAltsNumPatterns (matchAlts : Syntax) : Nat :=
4444 let pats := alt0[1 ][0 ].getSepArgs
4545 pats.size
4646
47+ open TSyntax.Compat in
4748/--
4849 Expand a match alternative such as `| 0 | 1 => rhs` to an array containing `| 0 => rhs` and `| 1 => rhs`.
4950-/
5051def expandMatchAlt (stx : TSyntax ``matchAlt) : MacroM (Array (TSyntax ``matchAlt)) :=
51- match stx with
52- | `(matchAltExpr| | $[$patss,*]|* => $rhs) =>
53- if patss.size ≤ 1 then
54- return #[stx]
55- else
56- patss.mapM fun pats => `(matchAltExpr| | $pats,* => $rhs)
57- | _ => return #[stx]
52+ -- Not using syntax quotations here to keep source location
53+ -- of the pattern sequence (`$term,*`) intact
54+ let patss := stx.raw[ 1 ].getSepArgs
55+ if patss.size ≤ 1 then
56+ return #[stx]
57+ else
58+ return patss.map fun pats => stx.raw.setArg 1 (mkNullNode #[pats])
5859
5960def shouldExpandMatchAlt : TSyntax ``matchAlt → Bool
6061 | `(matchAltExpr| | $[$patss,*]|* => $_) => patss.size > 1
Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ def getMatchAlt : Syntax → Option MatchAltView
165165 | alt@`(matchAltExpr| | $patterns,* => $rhs) => some {
166166 ref := alt,
167167 patterns := patterns,
168- lhs := alt[1 ],
168+ lhs := alt[1 ], -- this is the ref `$patterns,*`
169169 rhs := rhs
170170 }
171171 | _ => none
You can’t perform that action at this time.
0 commit comments