feat(frontends/lean): change the name resolution rules: when in a namespace N that defines C, then C always refers to N.C (i.e., it overrides any alias)

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-08-18 18:46:37 -07:00
parent 08ae17650b
commit f0d50e0d33
3 changed files with 36 additions and 15 deletions

View file

@ -941,26 +941,28 @@ expr parser::id_to_expr(name const & id, pos_info const & p) {
save_identifier_info(p, id);
return r;
}
} else {
lean_assert(!id.is_atomic());
name new_id = remove_root_prefix(id);
}
for (name const & ns : get_namespaces(m_env)) {
auto new_id = ns + id;
if (!ns.is_anonymous() && m_env.find(new_id)) {
auto r = save_pos(mk_constant(new_id, ls), p);
save_type_info(r);
add_ref_index(new_id, p);
save_identifier_info(p, new_id);
return r;
}
}
if (!id.is_atomic()) {
name new_id = id;
new_id = remove_root_prefix(new_id);
if (m_env.find(new_id)) {
auto r = save_pos(mk_constant(new_id, ls), p);
save_type_info(r);
add_ref_index(new_id, p);
save_identifier_info(p, new_id);
return r;
} else {
for (name const & ns : get_namespaces(m_env)) {
auto new_id = ns + id;
if (m_env.find(new_id)) {
auto r = save_pos(mk_constant(new_id, ls), p);
save_type_info(r);
add_ref_index(new_id, p);
save_identifier_info(p, new_id);
return r;
}
}
}
}

19
tests/lean/run/ns.lean Normal file
View file

@ -0,0 +1,19 @@
variable nat : Type.{1}
variable f : nat → nat
namespace foo
variable int : Type.{1}
variable f : int → int
variable a : nat
variable i : int
check _root_.f a
check f i
end foo
using foo
variables a : nat
variables i : int
check f a
check f i

View file

@ -11,7 +11,7 @@ C : Type
t4.lean:25:6: error: unknown identifier 'A'
R : Type → Prop
λ (x y : N), x : N → N → N
[choice N N]
N
N
N
M