feat: quotation precheck for choice nodes

This commit is contained in:
Sebastian Ullrich 2022-03-24 19:04:55 +01:00
parent c7321e0061
commit 6dfddbe2e7
3 changed files with 20 additions and 1 deletions

View file

@ -128,6 +128,14 @@ private def isSectionVariable (e : Expr) : TermElabM Bool := do
es.getElems.forM precheck
| _ => throwUnsupportedSyntax
@[builtinQuotPrecheck choice] def precheckChoice : Precheck := fun stx => do
let checks ← stx.getArgs.mapM (_root_.observing ∘ precheck)
let fails := checks.zip stx.getArgs |>.filterMap fun
| (.error e, stx) => some m!"{stx}\n{e.toMessageData}"
| _ => none
unless fails.isEmpty do
throwErrorAt stx "ambiguous notation with at least one interpretation that failed quotation precheck, possible interpretations {indentD (MessageData.joinSep fails.toList m!"\n\n")}"
@[builtinTermElab precheckedQuot] def elabPrecheckedQuot : TermElab := fun stx expectedType? => do
let singleQuot := stx[1]
runPrecheck singleQuot.getQuotContent

View file

@ -3,6 +3,11 @@ notation "a" => fun x => a
syntax "b" term : term
notation "c" => b x
set_option quotPrecheck false
set_option quotPrecheck false in
notation "d" => b x
#check d
infix:10 " ∧ " => and
set_option pp.raw true
notation "foo" => fun x y => x ∧ y
notation "bar" => fun x => x ∧ y

View file

@ -4,3 +4,9 @@ notationPrecheck.lean:4:16-4:19: error: no macro or `[quotPrecheck]` instance fo
This means we cannot eagerly check your notation/quotation for unbound identifiers; you can use `set_option quotPrecheck false` to disable this check.
notationPrecheck.lean:8:7-8:8: error: elaboration function for 'termB_' has not been implemented
b x✝
notationPrecheck.lean:13:27-13:32: error: ambiguous notation with at least one interpretation that failed quotation precheck, possible interpretations
(«term_∧__1» `x "∧" `y)
unknown identifier 'y' at quotation precheck; you can use `set_option quotPrecheck false` to disable this check.
(«term_∧_» `x "∧" `y)
unknown identifier 'y' at quotation precheck; you can use `set_option quotPrecheck false` to disable this check.