Skip to content

Commit 43f448f

Browse files
committed
This at least works, though probably not the way to do it
1 parent 639476f commit 43f448f

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

src/Lean/Elab/Match.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {α} (ref : Syntax) (patternVarDecls : Array PatternVarDecl) (patternStxs : Array Syntax) (lhsStx : Syntax) (numDiscrs : Nat) (matchType : Expr)
762+
private def withElaboratedLHS {α} (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 := ref, fvarDecls := localDecls.toList, patterns := patterns.toList } matchType
768+
k { ref := lhsStx, 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 alt.ref patternVarDecls alt.patterns alt.lhs discrs.size matchType fun altLHS matchType =>
820+
withElaboratedLHS 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}"

tests/lean/1057.lean.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1057.lean:9:2-9:28: error: Dependent elimination failed: Type mismatch when solving this alternative: it has type
1+
1057.lean:9:4-9:15: error: Dependent elimination failed: Type mismatch when solving this alternative: it has type
22
motive t Int
33
but is expected to have type
44
motive t x✝

tests/lean/match1.lean.expected.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
4
1111
---- inv
1212
10
13-
match1.lean:82:0-82:73: error: Dependent elimination failed: Type mismatch when solving this alternative: it has type
13+
match1.lean:82:2-82:60: error: Dependent elimination failed: Type mismatch when solving this alternative: it has type
1414
motive 0 (Vec.cons head✝ Vec.nil) ⋯
1515
but is expected to have type
1616
motive x✝ (Vec.cons head✝ tail✝) ⋯
1717
[false, true, true]
18-
match1.lean:119:0-119:41: error: Dependent match elimination failed: Expected a constructor, but found the inaccessible pattern
18+
match1.lean:119:2-119:18: error: Dependent match elimination failed: Expected a constructor, but found the inaccessible pattern
1919
.(j + j)
2020
[false, true, true]
2121
match1.lean:136:7-136:22: error: Invalid match expression: The type of pattern variable 'a' contains metavariables:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
redundantAlt.lean:5:1-5:9: error(lean.redundantMatchAlt): Redundant alternative: Any expression matching
1+
redundantAlt.lean:5:3-5:4: error(lean.redundantMatchAlt): Redundant alternative: Any expression matching
22
2
33
will match one of the preceding alternatives
4-
redundantAlt.lean:7:1-7:9: error(lean.redundantMatchAlt): Redundant alternative: Any expression matching
4+
redundantAlt.lean:7:3-7:4: error(lean.redundantMatchAlt): Redundant alternative: Any expression matching
55
3
66
will match one of the preceding alternatives

tests/lean/run/issue10781.lean

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/--
2+
@ +4:4...8
3+
error: Redundant alternative: Any expression matching
4+
0, x✝
5+
will match one of the preceding alternatives
6+
-/
7+
#guard_msgs (positions := true) in
8+
example : Nat → Nat → Nat
9+
| _ + 1, _ => 2 -- error was here (bad)
10+
| 0, _
11+
| 0, _ => 1 -- now error is here (good)
12+
13+
/--
14+
@ +4:4...8
15+
error: Redundant alternative: Any expression matching
16+
0, x✝
17+
will match one of the preceding alternatives
18+
-/
19+
#guard_msgs (positions := true) in
20+
example : Nat → Nat → Nat
21+
| _ + 1, _ => 2
22+
| 0, _ => 1
23+
| 0, _ => 1 -- error here (good)
24+
25+
/--
26+
@ +3:4...12
27+
error: Redundant alternative: Any expression matching
28+
n✝.succ.succ, x✝
29+
will match one of the preceding alternatives
30+
-/
31+
#guard_msgs (positions := true) in
32+
example : Nat → Nat → Nat
33+
| _ + 2, _ => 2
34+
| _ + 2, _ => 2 -- error here (good)
35+
| 0, _
36+
| 1, _ => 1

tests/lean/typeIncorrectPat.lean.expected.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
typeIncorrectPat.lean:2:1-2:17: error: Type mismatch in pattern: Pattern
1+
typeIncorrectPat.lean:2:3-2:12: error: Type mismatch in pattern: Pattern
22
true
33
has type
44
Bool

0 commit comments

Comments
 (0)