Skip to content

Commit

Permalink
fix: withMainContext in type_check tactic (#15533)
Browse files Browse the repository at this point in the history
Fixing a problem about `type_check` tactic: If you don't use `withMainContext`, you can't use local hypotheses and definitions produced by tactics before the `type_check` tactic, only can use hypotheses written on `theorem` header.
  • Loading branch information
znssong authored and bjoernkjoshanssen committed Sep 11, 2024
1 parent 83f8a5e commit 369e73d
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions Mathlib/Tactic/TypeCheck.lean
Original file line number Diff line number Diff line change
@@ -4,17 +4,19 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Lean.Elab.Tactic.Basic
import Lean.Elab.SyntheticMVars

/-!
# The `type_check` tactic
Define the `type_check` tactic: it type checks a given expression, and traces its type.
-/

open Lean Meta
open Lean Elab Meta

/-- Type check the given expression, and trace its type. -/
elab tk:"type_check " e:term : tactic => do
let e ← Lean.Elab.Term.elabTerm e none
check e
let type ← inferType e
Lean.logInfoAt tk f!"{← Lean.instantiateMVars type}"
Tactic.withMainContext do
let e ← Term.elabTermAndSynthesize e none
check e
let type ← inferType e
Lean.logInfoAt tk m!"{← Lean.instantiateMVars type}"
5 changes: 4 additions & 1 deletion test/TypeCheck.lean
Original file line number Diff line number Diff line change
@@ -17,7 +17,9 @@ info: Prop
---
info: Prop
---
info: Nat -> Nat
info: Nat → Nat
---
info: List Nat
-/
#guard_msgs in
example : True := by
@@ -28,5 +30,6 @@ example : True := by
type_check (True : _) -- Prop
type_check ∀ x y : Nat, x = y -- Prop
type_check fun x : Nat => 2 * x + 1 -- Nat -> Nat
type_check [1]
fail_if_success type_check wrong
trivial

0 comments on commit 369e73d

Please sign in to comment.