feat: empty type ascription syntax (e :) (part 2)

This commit is contained in:
Mario Carneiro 2022-11-03 08:05:10 -04:00 committed by Sebastian Ullrich
parent 2cd11d22af
commit 32b6bd0d8b
7 changed files with 36 additions and 7 deletions

View file

@ -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

View file

@ -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`

View file

@ -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;

View file

@ -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 \"_\")"

View file

@ -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₂ :)

View file

@ -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

View file

@ -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}}