fix(frontends/lean/parser): fixes #858
This commit is contained in:
parent
8b3cbb8fdd
commit
1abaa9eb71
6 changed files with 28 additions and 1 deletions
|
@ -144,7 +144,7 @@ static environment declare_var(parser & p, environment env,
|
||||||
if (k == variable_kind::Parameter)
|
if (k == variable_kind::Parameter)
|
||||||
p.add_parameter(n, l);
|
p.add_parameter(n, l);
|
||||||
else
|
else
|
||||||
p.add_local_expr(n, l, k == variable_kind::Variable);
|
p.add_variable(n, l);
|
||||||
return env;
|
return env;
|
||||||
} else {
|
} else {
|
||||||
lean_assert(k == variable_kind::Constant || k == variable_kind::Axiom);
|
lean_assert(k == variable_kind::Constant || k == variable_kind::Axiom);
|
||||||
|
|
|
@ -604,8 +604,28 @@ environment parser::add_local_ref(environment const & env, name const & n, expr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void check_no_metavars(name const & n, expr const & e) {
|
||||||
|
lean_assert(is_local(e));
|
||||||
|
if (has_metavar(e)) {
|
||||||
|
throw_generic_exception(none_expr(), [=](formatter const & fmt) {
|
||||||
|
format r("failed to add declaration '");
|
||||||
|
r += format(n);
|
||||||
|
r += format("' to local context, type has metavariables");
|
||||||
|
r += pp_until_meta_visible(fmt, mlocal_type(e));
|
||||||
|
return r;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void parser::add_variable(name const & n, expr const & v) {
|
||||||
|
lean_assert(is_local(v));
|
||||||
|
check_no_metavars(n, v);
|
||||||
|
add_local_expr(n, v, true);
|
||||||
|
}
|
||||||
|
|
||||||
void parser::add_parameter(name const & n, expr const & p) {
|
void parser::add_parameter(name const & n, expr const & p) {
|
||||||
lean_assert(is_local(p));
|
lean_assert(is_local(p));
|
||||||
|
check_no_metavars(n, p);
|
||||||
add_local_expr(n, p, false);
|
add_local_expr(n, p, false);
|
||||||
m_has_params = true;
|
m_has_params = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -470,6 +470,7 @@ public:
|
||||||
void add_local_level(name const & n, level const & l, bool is_variable = false);
|
void add_local_level(name const & n, level const & l, bool is_variable = false);
|
||||||
void add_local_expr(name const & n, expr const & p, bool is_variable = false);
|
void add_local_expr(name const & n, expr const & p, bool is_variable = false);
|
||||||
environment add_local_ref(environment const & env, name const & n, expr const & ref);
|
environment add_local_ref(environment const & env, name const & n, expr const & ref);
|
||||||
|
void add_variable(name const & n, expr const & p);
|
||||||
void add_parameter(name const & n, expr const & p);
|
void add_parameter(name const & n, expr const & p);
|
||||||
void add_local(expr const & p) { return add_local_expr(local_pp_name(p), p); }
|
void add_local(expr const & p) { return add_local_expr(local_pp_name(p), p); }
|
||||||
bool has_params() const { return m_has_params; }
|
bool has_params() const { return m_has_params; }
|
||||||
|
|
|
@ -30,4 +30,5 @@ struct scoped_set_distinguishing_pp_options {
|
||||||
~scoped_set_distinguishing_pp_options() { set_distinguishing_pp_options(m_old); }
|
~scoped_set_distinguishing_pp_options() { set_distinguishing_pp_options(m_old); }
|
||||||
};
|
};
|
||||||
std::tuple<format, format> pp_until_different(formatter const & fmt, expr const & e1, expr const & e2);
|
std::tuple<format, format> pp_until_different(formatter const & fmt, expr const & e1, expr const & e2);
|
||||||
|
format pp_until_meta_visible(formatter const & fmt, expr const & e);
|
||||||
}
|
}
|
||||||
|
|
3
tests/lean/858.lean
Normal file
3
tests/lean/858.lean
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
section
|
||||||
|
parameter (n : Πa, nat)
|
||||||
|
end
|
2
tests/lean/858.lean.expected.out
Normal file
2
tests/lean/858.lean.expected.out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
858.lean:2:2: error: failed to add declaration 'n' to local context, type has metavariables
|
||||||
|
?M_1 → ℕ
|
Loading…
Reference in a new issue