fix(frontends/lean/elaborator): unintended use of local instances

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-07-04 18:49:05 -07:00
parent 99fb6431a6
commit 4af474010a
3 changed files with 10 additions and 2 deletions

View file

@ -95,6 +95,11 @@ environment add_instance(environment const & env, name const & n) {
return class_ext::add_entry(env, get_dummy_ios(), class_entry(c, n));
}
bool is_class(environment const & env, name const & c) {
class_state const & s = class_ext::get_state(env);
return s.m_instances.contains(c);
}
list<name> get_class_instances(environment const & env, name const & c) {
class_state const & s = class_ext::get_state(env);
if (auto it = s.m_instances.find(c))

View file

@ -15,6 +15,8 @@ namespace lean {
environment add_class(environment const & env, name const & n);
/** \brief Add a new 'class instance' to the environment. */
environment add_instance(environment const & env, name const & n);
/** \brief Return true iff \c c was declared with \c add_class . */
bool is_class(environment const & env, name const & c);
/** \brief Return the instances of the given class. */
list<name> get_class_instances(environment const & env, name const & c);

View file

@ -374,7 +374,8 @@ public:
}
bool is_class(expr const & type) {
return !empty(get_class_instances(type));
expr f = get_app_fn(type);
return is_constant(f) && ::lean::is_class(m_env, const_name(f));
}
bool may_be_class(expr const & type) {
@ -394,7 +395,7 @@ public:
context ctx = m_ctx;
justification j = mk_justification("failed to apply class instances", some_expr(m));
auto choice_fn = [=](expr const & mvar, expr const & mvar_type, substitution const & s, name_generator const & /* ngen */) {
if (!is_constant(get_app_fn(mvar_type)))
if (!is_class(mvar_type))
return lazy_list<constraints>(constraints());
list<expr> local_insts;
if (m_use_local_instances) {