diff --git a/src/Lean/Elab/Do.lean b/src/Lean/Elab/Do.lean index b31f5821e3..a4a23b3dd5 100644 --- a/src/Lean/Elab/Do.lean +++ b/src/Lean/Elab/Do.lean @@ -12,9 +12,6 @@ import Lean.Parser.Do -- HACK: avoid code explosion until heuristics are improved set_option compiler.reuse false --- remove after stage0 update -set_option quotPrecheck false - namespace Lean.Elab.Term open Lean.Parser.Term open Meta diff --git a/src/Lean/Parser/Term.lean b/src/Lean/Parser/Term.lean index 7f2bbc1617..903e16123d 100644 --- a/src/Lean/Parser/Term.lean +++ b/src/Lean/Parser/Term.lean @@ -130,6 +130,9 @@ Parentheses, used for - Grouping expressions, e.g., `a * (b + c)`. - Creating tuples, e.g., `(a, b, c)` is notation for `Prod.mk a (Prod.mk b c)`. - Performing type ascription, e.g., `(0 : Int)` instructs Lean to process `0` as a value of type `Int`. + - An empty type ascription `(e :)` elaborates `e` without the expected type. + This is occasionally useful when Lean's heuristics for filling arguments from the expected type + do not yield the right result. - Creating `Unit.unit`, `()` is just a shorthand for `Unit.unit`. - Creating simple functions when combined with `·`. Here are some examples: - `(· + 1)` is shorthand for `fun x => x + 1` diff --git a/stage0/src/stdlib_flags.h b/stage0/src/stdlib_flags.h index aae6413ccc..214489ca50 100644 --- a/stage0/src/stdlib_flags.h +++ b/stage0/src/stdlib_flags.h @@ -8,7 +8,7 @@ options get_default_options() { // switch to `true` for ABI-breaking changes affecting meta code opts = opts.update({"interpreter", "prefer_native"}, false); // switch to `true` for changing built-in parsers used in quotations - opts = opts.update({"internal", "parseQuotWithCurrentStage"}, false); + opts = opts.update({"internal", "parseQuotWithCurrentStage"}, true); opts = opts.update({"pp", "rawOnError"}, true); #endif return opts; diff --git a/tests/lean/StxQuot.lean.expected.out b/tests/lean/StxQuot.lean.expected.out index c212ad1fe8..d2224f2bb1 100644 --- a/tests/lean/StxQuot.lean.expected.out +++ b/tests/lean/StxQuot.lean.expected.out @@ -24,8 +24,8 @@ StxQuot.lean:19:15: error: expected term 0 1 "1" -"(Term.fun\n \"fun\"\n (Term.basicFun\n [`a._@.UnhygienicMain._hyg.1\n (Term.paren \"(\" [`b._@.UnhygienicMain._hyg.1 [(Term.typeAscription \":\" `Nat._@.UnhygienicMain._hyg.1)]] \")\")]\n []\n \"=>\"\n (num \"1\")))" -"#[(Term.paren \"(\" [`a._@.UnhygienicMain._hyg.1 [(Term.typeAscription \":\" `Nat._@.UnhygienicMain._hyg.1)]] \")\"), `b._@.UnhygienicMain._hyg.1]" +"(Term.fun\n \"fun\"\n (Term.basicFun\n [`a._@.UnhygienicMain._hyg.1\n (Term.paren \"(\" [`b._@.UnhygienicMain._hyg.1 [(Term.typeAscription \":\" [`Nat._@.UnhygienicMain._hyg.1])]] \")\")]\n []\n \"=>\"\n (num \"1\")))" +"#[(Term.paren \"(\" [`a._@.UnhygienicMain._hyg.1 [(Term.typeAscription \":\" [`Nat._@.UnhygienicMain._hyg.1])]] \")\"), `b._@.UnhygienicMain._hyg.1]" "`a._@.UnhygienicMain._hyg.1" "(Term.forall \"∀\" [(Term.hole \"_\")] [] \",\" `c._@.UnhygienicMain._hyg.1)" "(Term.hole \"_\")" diff --git a/tests/lean/emptyTypeAscription.lean b/tests/lean/emptyTypeAscription.lean new file mode 100644 index 0000000000..d63daff3a4 --- /dev/null +++ b/tests/lean/emptyTypeAscription.lean @@ -0,0 +1,11 @@ +example : Nat := ( .zero : Nat) +example : Nat := ( .zero : _) +example : Nat := ( .zero :) -- fail +example : Nat := by have' := .zero; exact this -- fail + +def add (x y : Nat) := x + y + +example (h₁ : z = x + y) (h₂ : w = z) : w = add x y := have := h₁ ▸ h₂; by exact this +example (h₁ : z = x + y) (h₂ : w = z) : w = add x y := have := h₁ ▸ h₂; this -- fail +example (h₁ : z = x + y) (h₂ : w = z) : w = add x y := h₁ ▸ h₂ -- fail +example (h₁ : z = x + y) (h₂ : w = z) : w = add x y := (h₁ ▸ h₂ :) diff --git a/tests/lean/emptyTypeAscription.lean.expected.out b/tests/lean/emptyTypeAscription.lean.expected.out new file mode 100644 index 0000000000..637b8edde4 --- /dev/null +++ b/tests/lean/emptyTypeAscription.lean.expected.out @@ -0,0 +1,18 @@ +emptyTypeAscription.lean:3:19-3:24: error: invalid dotted identifier notation, expected type is not of the form (... → C ...) where C is a constant + ?m +emptyTypeAscription.lean:4:29-4:34: error: invalid dotted identifier notation, expected type is not of the form (... → C ...) where C is a constant + ?m +emptyTypeAscription.lean:9:63-9:70: error: invalid `▸` notation, expected result type of cast is + w = add x y +however, the equality + h₁ +of type + z = x + y +does not contain the expected result type on either the left or the right hand side +emptyTypeAscription.lean:10:55-10:62: error: invalid `▸` notation, expected result type of cast is + w = add x y +however, the equality + h₁ +of type + z = x + y +does not contain the expected result type on either the left or the right hand side diff --git a/tests/lean/interactive/hover.lean.expected.out b/tests/lean/interactive/hover.lean.expected.out index 8654ab8f90..fa4d1e6232 100644 --- a/tests/lean/interactive/hover.lean.expected.out +++ b/tests/lean/interactive/hover.lean.expected.out @@ -380,7 +380,7 @@ null "end": {"line": 198, "character": 32}}, "contents": {"value": - "```lean\nId ℕ\n```\n***\nParentheses, used for\n- Grouping expressions, e.g., `a * (b + c)`.\n- Creating tuples, e.g., `(a, b, c)` is notation for `Prod.mk a (Prod.mk b c)`.\n- Performing type ascription, e.g., `(0 : Int)` instructs Lean to process `0` as a value of type `Int`.\n- Creating `Unit.unit`, `()` is just a shorthand for `Unit.unit`.\n- Creating simple functions when combined with `·`. Here are some examples:\n - `(· + 1)` is shorthand for `fun x => x + 1`\n - `(· + ·)` is shorthand for `fun x y => x + y`\n - `(f · a b)` is shorthand for `fun x => f x a b`\n - `(h (· + 1) ·)` is shorthand for `fun x => h (fun y => y + 1) x`\n", + "```lean\nId ℕ\n```\n***\nParentheses, used for\n- Grouping expressions, e.g., `a * (b + c)`.\n- Creating tuples, e.g., `(a, b, c)` is notation for `Prod.mk a (Prod.mk b c)`.\n- Performing type ascription, e.g., `(0 : Int)` instructs Lean to process `0` as a value of type `Int`.\n - An empty type ascription `(e :)` elaborates `e` without the expected type.\n This is occasionally useful when Lean's heuristics for filling arguments from the expected type\n do not yield the right result.\n- Creating `Unit.unit`, `()` is just a shorthand for `Unit.unit`.\n- Creating simple functions when combined with `·`. Here are some examples:\n - `(· + 1)` is shorthand for `fun x => x + 1`\n - `(· + ·)` is shorthand for `fun x y => x + y`\n - `(f · a b)` is shorthand for `fun x => f x a b`\n - `(h (· + 1) ·)` is shorthand for `fun x => h (fun y => y + 1) x`\n", "kind": "markdown"}} {"textDocument": {"uri": "file://hover.lean"}, "position": {"line": 201, "character": 8}}