fix(frontends/lean/elaborator): unintended use of local instances
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
99fb6431a6
commit
4af474010a
3 changed files with 10 additions and 2 deletions
|
@ -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));
|
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) {
|
list<name> get_class_instances(environment const & env, name const & c) {
|
||||||
class_state const & s = class_ext::get_state(env);
|
class_state const & s = class_ext::get_state(env);
|
||||||
if (auto it = s.m_instances.find(c))
|
if (auto it = s.m_instances.find(c))
|
||||||
|
|
|
@ -15,6 +15,8 @@ namespace lean {
|
||||||
environment add_class(environment const & env, name const & n);
|
environment add_class(environment const & env, name const & n);
|
||||||
/** \brief Add a new 'class instance' to the environment. */
|
/** \brief Add a new 'class instance' to the environment. */
|
||||||
environment add_instance(environment const & env, name const & n);
|
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. */
|
/** \brief Return the instances of the given class. */
|
||||||
list<name> get_class_instances(environment const & env, name const & c);
|
list<name> get_class_instances(environment const & env, name const & c);
|
||||||
|
|
||||||
|
|
|
@ -374,7 +374,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_class(expr const & type) {
|
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) {
|
bool may_be_class(expr const & type) {
|
||||||
|
@ -394,7 +395,7 @@ public:
|
||||||
context ctx = m_ctx;
|
context ctx = m_ctx;
|
||||||
justification j = mk_justification("failed to apply class instances", some_expr(m));
|
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 */) {
|
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());
|
return lazy_list<constraints>(constraints());
|
||||||
list<expr> local_insts;
|
list<expr> local_insts;
|
||||||
if (m_use_local_instances) {
|
if (m_use_local_instances) {
|
||||||
|
|
Loading…
Reference in a new issue