feat(frontends/lean): do not allow coercion definition in sections
This commit is contained in:
parent
78b8a67015
commit
549f24335e
4 changed files with 28 additions and 1 deletions
|
@ -377,6 +377,8 @@ environment open_cmd(parser & p) { return open_export_cmd(p, true); }
|
|||
environment export_cmd(parser & p) { return open_export_cmd(p, false); }
|
||||
|
||||
environment coercion_cmd(parser & p) {
|
||||
if (in_context(p.env()))
|
||||
throw parser_error("invalid 'coercion' command, coercions cannot be defined in contexts", p.pos());
|
||||
bool persistent = false;
|
||||
parse_persistent(p, persistent);
|
||||
name f = p.check_constant_next("invalid 'coercion' command, constant expected");
|
||||
|
|
|
@ -279,8 +279,11 @@ struct decl_modifiers {
|
|||
m_is_instance = true;
|
||||
p.next();
|
||||
} else if (p.curr_is_token(get_coercion_tk())) {
|
||||
m_is_coercion = true;
|
||||
auto pos = p.pos();
|
||||
p.next();
|
||||
if (in_context(p.env()))
|
||||
throw parser_error("invalid '[coercion]' modifier, coercions cannot be defined in contexts", pos);
|
||||
m_is_coercion = true;
|
||||
} else if (p.curr_is_token(get_reducible_tk())) {
|
||||
m_is_reducible = true;
|
||||
p.next();
|
||||
|
|
20
tests/lean/bad_coercions.lean
Normal file
20
tests/lean/bad_coercions.lean
Normal file
|
@ -0,0 +1,20 @@
|
|||
import data.nat.basic
|
||||
open nat
|
||||
|
||||
constant list.{l} : Type.{l} → Type.{l}
|
||||
constant vector.{l} : Type.{l} → nat → Type.{l}
|
||||
constant nil (A : Type) : list A
|
||||
|
||||
set_option pp.coercions true
|
||||
context
|
||||
parameter A : Type
|
||||
parameter n : nat
|
||||
|
||||
definition foo2 [coercion] (v : vector A n) : list A :=
|
||||
nil A
|
||||
|
||||
definition foo (v : vector A n) : list A :=
|
||||
nil A
|
||||
|
||||
coercion foo
|
||||
end
|
2
tests/lean/bad_coercions.lean.expected.out
Normal file
2
tests/lean/bad_coercions.lean.expected.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
bad_coercions.lean:13:18: error: invalid '[coercion]' modifier, coercions cannot be defined in contexts
|
||||
bad_coercions.lean:19:11: error: invalid 'coercion' command, coercions cannot be defined in contexts
|
Loading…
Add table
Reference in a new issue