Skip to content

Commit 639476f

Browse files
committed
Revert "fix: preserve error locations when expanding match arms"
This reverts commit 92981df.
1 parent 92981df commit 639476f

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

src/Lean/Elab/BindersUtil.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ open Lean.Parser.Term
4141
/-- Helper function for `expandEqnsIntoMatch` -/
4242
def getMatchAltsNumPatterns (matchAlts : Syntax) : Nat :=
4343
let alt0 := matchAlts[0][0]
44-
let pats := alt0[1][0][0].getSepArgs
44+
let pats := alt0[1][0].getSepArgs
4545
pats.size
4646

4747
/--
4848
Expand a match alternative such as `| 0 | 1 => rhs` to an array containing `| 0 => rhs` and `| 1 => rhs`.
4949
-/
5050
def expandMatchAlt (stx : TSyntax ``matchAlt) : MacroM (Array (TSyntax ``matchAlt)) :=
5151
match stx with
52-
| `(matchAltExpr| | $[$patss:matchAltPats]|* => $rhs) => do
52+
| `(matchAltExpr| | $[$patss,*]|* => $rhs) =>
5353
if patss.size ≤ 1 then
5454
return #[stx]
5555
else
56-
patss.mapM fun pats => `(matchAltExpr| | $pats => $rhs)
56+
patss.mapM fun pats => `(matchAltExpr| | $pats,* => $rhs)
5757
| _ => return #[stx]
5858

5959
def shouldExpandMatchAlt : TSyntax ``matchAlt → Bool
60-
| `(matchAltExpr| | $[$patss:matchAltPats]|* => $_) => patss.size > 1
60+
| `(matchAltExpr| | $[$patss,*]|* => $_) => patss.size > 1
6161
| _ => false
6262

6363
def expandMatchAlts? (stx : Syntax) : MacroM (Option Syntax) := do

src/Lean/Elab/Match.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ private def getMatchGeneralizing? : Syntax → Option Bool
162162

163163
/-- Given the `stx` of a single match alternative, return a corresponding `MatchAltView`. -/
164164
def getMatchAlt : Syntax → Option MatchAltView
165-
| alt@`(matchAltExpr| | $patterns:matchAltPats => $rhs) => some {
165+
| alt@`(matchAltExpr| | $patterns,* => $rhs) => some {
166166
ref := alt,
167-
patterns := patterns.raw[0].getSepArgs,
168-
lhs := patterns,
167+
patterns := patterns,
168+
lhs := alt[1],
169169
rhs := rhs
170170
}
171171
| _ => none
@@ -759,13 +759,13 @@ end ToDepElimPattern
759759
def withDepElimPatterns (patternVarDecls : Array PatternVarDecl) (ps : Array Expr) (matchType : Expr) (k : Array LocalDecl → Array Pattern → Expr → TermElabM α) : TermElabM α := do
760760
ToDepElimPattern.main patternVarDecls ps matchType k
761761

762-
private def withElaboratedLHS {α} (patternVarDecls : Array PatternVarDecl) (patternStxs : Array Syntax) (lhsStx : Syntax) (numDiscrs : Nat) (matchType : Expr)
762+
private def withElaboratedLHS {α} (ref : Syntax) (patternVarDecls : Array PatternVarDecl) (patternStxs : Array Syntax) (lhsStx : Syntax) (numDiscrs : Nat) (matchType : Expr)
763763
(k : AltLHS → Expr → TermElabM α) : ExceptT PatternElabException TermElabM α := do
764764
let (patterns, matchType) ← withSynthesize <| withRef lhsStx <| elabPatterns patternStxs numDiscrs matchType
765765
id (α := TermElabM α) do
766766
trace[Elab.match] "patterns: {patterns}"
767767
withDepElimPatterns patternVarDecls patterns matchType fun localDecls patterns matchType => do
768-
k { ref := lhsStx, fvarDecls := localDecls.toList, patterns := patterns.toList } matchType
768+
k { ref := ref, fvarDecls := localDecls.toList, patterns := patterns.toList } matchType
769769

770770
/--
771771
Try to clear the free variables in `toClear` and auxiliary discriminants, and then execute `k` in the updated local context.
@@ -817,7 +817,7 @@ private def elabMatchAltView (discrs : Array Discr) (alt : MatchAltView) (matchT
817817
let (patternVars, alt) ← collectPatternVars alt
818818
trace[Elab.match] "patternVars: {patternVars}"
819819
withPatternVars patternVars fun patternVarDecls => do
820-
withElaboratedLHS patternVarDecls alt.patterns alt.lhs discrs.size matchType fun altLHS matchType =>
820+
withElaboratedLHS alt.ref patternVarDecls alt.patterns alt.lhs discrs.size matchType fun altLHS matchType =>
821821
withEqs discrs altLHS.patterns fun eqs =>
822822
withLocalInstances altLHS.fvarDecls do
823823
trace[Elab.match] "elabMatchAltView: {matchType}"

src/Lean/Parser/Term.lean

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,10 @@ def «forall» := leading_parser:leadPrec
259259
many1 (ppSpace >> (binderIdent <|> bracketedBinder)) >>
260260
optType >> ", " >> termParser
261261

262-
def matchAltPats : Parser := leading_parser
263-
sepBy1 termParser ", "
264-
265262
def matchAlt (rhsParser : Parser := termParser) : Parser :=
266263
leading_parser (withAnonymousAntiquot := false)
267264
"| " >> ppIndent (
268-
sepBy1 matchAltPats " | " >> darrow >>
265+
sepBy1 (sepBy1 termParser ", ") " | " >> darrow >>
269266
checkColGe "alternative right-hand-side to start in a column greater than or equal to the corresponding '|'" >>
270267
rhsParser)
271268
/--

0 commit comments

Comments
 (0)