lean4-htt/tests/lean/run/issue5562.lean
Joachim Breitner d4fdb5d7c0
fix: getFunInfo, inferType to use withAtLeastTransparency, not withTransparency (#5563)
when the transparency mode is `.all`, then one expects `getFunInfo` and
`inferType` to also work with that transparency mode.

Fixes #5562
Fixes #2975 
Fixes #2194
2024-10-04 13:04:35 +00:00

63 lines
1.1 KiB
Text

import Lean
/-!
This test checks that we can enter, typecheck etc. terms that are only type-correct at
transparency `all`.
-/
open Lean Meta
def T := Nat → Nat
def x : T := fun n => n + 1
-- All well:
def n1 : Nat := x 1
-- Now we make `T` irreducible. A bunch of things should break:
attribute [irreducible] T
/--
error: function expected at
x
term has type
T
-/
#guard_msgs in
def n2 : Nat := x 1
-- NB: Checking does not break! Always done at transparency `all`.
run_meta do
Meta.check (.app (mkConst ``x) (mkNatLit 1))
-- Type inference fails:
/--
error: function expected
x 1
-/
#guard_msgs in
run_meta do
let _ ← Meta.inferType (.app (mkConst ``x) (mkNatLit 1))
-- But succeeds at transparency .all
run_meta do
withTransparency .all do
let _ ← Meta.inferType (.app (mkConst ``x) (mkNatLit 1))
-- An elaborator that sets transparency to .all:
elab "with_unfolding_all" t:term : term <= expectedType? =>
withTransparency .all <|
Elab.Term.elabTerm t expectedType?
/--
error: function expected
x 1
-/
#guard_msgs in
def n3 : Nat := with_unfolding_all x 1