Skip to content

Commit a8d6178

Browse files
digama0Kha
authored andcommitted
feat: implement have this (part 2)
1 parent 0c624d8 commit a8d6178

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/Lean/Elab/Deriving/DecEq.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def mkDecEqEnum (declName : Name) : CommandElabM Unit := do
166166
fun x y =>
167167
if h : x.toCtorIdx = y.toCtorIdx then
168168
-- We use `rfl` in the following proof because the first script fails for unit-like datatypes due to etaStruct.
169-
isTrue (by first | refine_lift let_fun aux := congrArg $ofNatIdent h; ?_; rw [$auxThmIdent:ident, $auxThmIdent:ident] at aux; assumption | rfl)
169+
isTrue (by first | have aux := congrArg $ofNatIdent h; rw [$auxThmIdent:ident, $auxThmIdent:ident] at aux; assumption | rfl)
170170
else
171171
isFalse fun h => by subst h; contradiction
172172
)

src/Lean/Elab/Do.lean

+7-7
Original file line numberDiff line numberDiff line change
@@ -624,25 +624,25 @@ def getDoLetVars (doLet : Syntax) : TermElabM (Array Var) :=
624624
-- leading_parser "let " >> optional "mut " >> letDecl
625625
getLetDeclVars doLet[2]
626626

627-
def getHaveIdLhsVar (optIdent : Syntax) : TermElabM Var :=
628-
if optIdent.isNone then
629-
`(this)
627+
def getHaveIdLhsVar (optIdent : Syntax) : Var :=
628+
if optIdent.getKind == hygieneInfoKind then
629+
HygieneInfo.mkIdent optIdent[0] `this
630630
else
631-
pure optIdent[0]
631+
optIdent
632632

633633
def getDoHaveVars (doHave : Syntax) : TermElabM (Array Var) := do
634634
-- doHave := leading_parser "have " >> Term.haveDecl
635635
-- haveDecl := leading_parser haveIdDecl <|> letPatDecl <|> haveEqnsDecl
636636
let arg := doHave[1][0]
637637
if arg.getKind == ``Parser.Term.haveIdDecl then
638638
-- haveIdDecl := leading_parser atomic (haveIdLhs >> " := ") >> termParser
639-
-- haveIdLhs := optional (ident >> many (ppSpace >> letIdBinder)) >> optType
640-
return #[getHaveIdLhsVar arg[0]]
639+
-- haveIdLhs := (binderIdent <|> hygieneInfo) >> many letIdBinder >> optType
640+
return #[getHaveIdLhsVar arg[0]]
641641
else if arg.getKind == ``Parser.Term.letPatDecl then
642642
getLetPatDeclVars arg
643643
else if arg.getKind == ``Parser.Term.haveEqnsDecl then
644644
-- haveEqnsDecl := leading_parser haveIdLhs >> matchAlts
645-
return #[getHaveIdLhsVar arg[0]]
645+
return #[getHaveIdLhsVar arg[0]]
646646
else
647647
throwError "unexpected kind of have declaration"
648648

tests/lean/1021.lean.expected.out

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
some { range := { pos := { line := 167, column := 42 },
1+
some { range := { pos := { line := 175, column := 42 },
22
charUtf16 := 42,
3-
endPos := { line := 173, column := 31 },
3+
endPos := { line := 181, column := 31 },
44
endCharUtf16 := 31 },
5-
selectionRange := { pos := { line := 167, column := 46 },
5+
selectionRange := { pos := { line := 175, column := 46 },
66
charUtf16 := 46,
7-
endPos := { line := 167, column := 58 },
7+
endPos := { line := 175, column := 58 },
88
endCharUtf16 := 58 } }

tests/lean/StxQuot.lean.expected.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ StxQuot.lean:19:15: error: expected term
4040
"(Term.match\n \"match\"\n []\n []\n [(Term.matchDiscr [] `[email protected]._hyg.1)]\n \"with\"\n (Term.matchAlts\n [(Term.matchAlt \"|\" [[`[email protected]._hyg.1]] \"=>\" `[email protected]._hyg.1)\n (Term.matchAlt\n \"|\"\n [[(«term_+_» `[email protected]._hyg.1 \"+\" (num \"1\"))]]\n \"=>\"\n («term_+_» `[email protected]._hyg.1 \"+\" (num \"1\")))]))"
4141
4242
"1"
43-
"(Term.sufficesDecl [] `[email protected]._hyg.1 (Term.fromTerm \"from\" `[email protected]._hyg.1))"
43+
"(Term.sufficesDecl\n (hygieneInfo `[email protected]._hyg.1)\n `[email protected]._hyg.1\n (Term.fromTerm \"from\" `[email protected]._hyg.1))"
4444
"#[(num \"1\"), [(num \"2\") (num \"3\")], (num \"4\")]"
4545
"#[(num \"2\")]"
4646
StxQuot.lean:95:39-95:44: error: unexpected antiquotation splice

0 commit comments

Comments
 (0)