New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - feat(Mathlib/Tactic/TypeCheck): add type_check
tactic
#318
[Merged by Bors] - feat(Mathlib/Tactic/TypeCheck): add type_check
tactic
#318
Conversation
Gotta add it to the |
test/TypeCheck.lean
Outdated
example : True := by { | ||
type_check Nat; -- Type | ||
type_check Bool.true; -- Bool | ||
type_check nat_lit 1; -- Nat | ||
type_check (1 : Nat); -- Nat | ||
type_check (True : _); -- Prop | ||
type_check ∀ x y : Nat, x = y; -- Prop | ||
type_check fun x : Nat => 2 * x + 1; -- Nat -> Nat | ||
exact True.intro } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example : True := by { | |
type_check Nat; -- Type | |
type_check Bool.true; -- Bool | |
type_check nat_lit 1; -- Nat | |
type_check (1 : Nat); -- Nat | |
type_check (True : _); -- Prop | |
type_check ∀ x y : Nat, x = y; -- Prop | |
type_check fun x : Nat => 2 * x + 1; -- Nat -> Nat | |
exact True.intro } | |
example : True := by | |
type_check Nat -- Type | |
type_check Bool.true -- Bool | |
type_check nat_lit 1 -- Nat | |
type_check (1 : Nat) -- Nat | |
type_check (True : _) -- Prop | |
type_check ∀ x y : Nat, x = y -- Prop | |
type_check fun x : Nat => 2 * x + 1 -- Nat -> Nat | |
trivial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs some type check error tests as well, using fail_if_success
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking as unresolved, as we still need to error tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand, can you explain in more detail what we need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g. fail_if_success type_check 2 + "hi"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#334 has an alternative expect_failure
tactic which should give you what you want here. We'll try to merge that soon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug in fail_if_success
/success_if_fail
/expect_failure
(the synonyms keep piling up...), not type_check
. As mentioned in the zulip thread, these tactics need to be wrapped in withoutRecover
(or possibly we need a !
variant of the tactic that uses this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@digama0 expect_failure
already uses withoutRecover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you suggest how we should be testing this?
I'm not 100% sure what type_check
is supposed to do, but I guess it's supposed to find bugs in proofs produced by tactics. So I would suggest to test a tactic or elaborator that produces a term which does not type check. Such as this one:
/-- A term where `inferType` returns `Prop`, but which does not type check. -/
elab "wrong" : term =>
return Lean.mkApp2 (.const ``id [.zero]) (.sort .zero) (.app (.sort .zero) (.sort .zero))
I have committed this elaborator and a failing test case.
Co-authored-by: Mario Carneiro <di.gama@gmail.com>
Co-authored-by: Scott Morrison <scott@tqft.net>
Thank! bors r+ |
Lean 3 version: https://github.com/leanprover-community/lean/blob/master/library/init/meta/interactive.lean#L1664 Co-authored-by: Gabriel Ebner <gebner@gebner.org>
Pull request successfully merged into master. Build succeeded: |
type_check
tactictype_check
tactic
Lean 3 version: https://github.com/leanprover-community/lean/blob/master/library/init/meta/interactive.lean#L1664