diff --git a/src/Lean/Elab/Quotation/Precheck.lean b/src/Lean/Elab/Quotation/Precheck.lean index 75428b578e..e3270464ec 100644 --- a/src/Lean/Elab/Quotation/Precheck.lean +++ b/src/Lean/Elab/Quotation/Precheck.lean @@ -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 diff --git a/tests/lean/notationPrecheck.lean b/tests/lean/notationPrecheck.lean index 5bee76f17d..431c7e7b09 100644 --- a/tests/lean/notationPrecheck.lean +++ b/tests/lean/notationPrecheck.lean @@ -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 diff --git a/tests/lean/notationPrecheck.lean.expected.out b/tests/lean/notationPrecheck.lean.expected.out index a1f123efaa..5caf532ffc 100644 --- a/tests/lean/notationPrecheck.lean.expected.out +++ b/tests/lean/notationPrecheck.lean.expected.out @@ -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.