feat(frontends/lean): do not allow coercion definition in sections

This commit is contained in:
Leonardo de Moura 2014-10-11 18:40:48 -07:00
parent 78b8a67015
commit 549f24335e
4 changed files with 28 additions and 1 deletions

View file

@ -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");

View file

@ -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();

View 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

View 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