fix: syntax pattern match against multiple identifiers

This commit is contained in:
Sebastian Ullrich 2021-06-10 18:15:40 +02:00
parent 47f3cac0c5
commit e4bf5977d9
3 changed files with 18 additions and 3 deletions

View file

@ -386,11 +386,19 @@ private partial def getHeadInfo (alt : Alt) : TermElabM HeadInfo :=
let kind := quoted.getKind
let argPats := quoted.getArgs.map fun arg => Unhygienic.run `(`($(arg)))
pure {
check := shape kind argPats.size,
check :=
if quoted.isIdent then
other quoted
else
shape kind argPats.size,
onMatch := fun
| other _ => undecided
| other stx' =>
if quoted.isIdent && quoted == stx' then
covered pure (exhaustive := true)
else
uncovered
| shape k' sz =>
if k' == kind && sz == argPats.size then
if k' == kind && sz == argPats.size && kind != `ident then
covered (fun (pats, rhs) => (argPats.toList ++ pats, rhs)) (exhaustive := true)
else
uncovered

View file

@ -107,3 +107,9 @@ syntax "foo" term : term
#eval run ``(fun x => y)
#eval run ``(fun x y => x y)
#eval run ``(fun ⟨x, y⟩ => x)
#eval run do
match mkIdent `b with
| `(a) => "0"
| `(b) => "1"
| _ => "2"

View file

@ -54,3 +54,4 @@ StxQuot.lean:101:13-101:14: error: unknown identifier 'x' at quotation precheck;
StxQuot.lean:107:22-107:23: error: unknown identifier 'y' at quotation precheck; you can use `set_option quotPrecheck false` to disable this check.
"(Term.fun\n \"fun\"\n (Term.basicFun\n [`x._@.UnhygienicMain._hyg.1 `y._@.UnhygienicMain._hyg.1]\n \"=>\"\n (Term.app `x._@.UnhygienicMain._hyg.1 [`y._@.UnhygienicMain._hyg.1])))"
"(Term.fun\n \"fun\"\n (Term.basicFun\n [(Term.anonymousCtor \"⟨\" [`x._@.UnhygienicMain._hyg.1 \",\" `y._@.UnhygienicMain._hyg.1] \"⟩\")]\n \"=>\"\n `x._@.UnhygienicMain._hyg.1))"
"1"