feat(kernel/type_checker): improve application type mismatch error messages
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
579b751e01
commit
b26035fcf6
6 changed files with 11 additions and 8 deletions
|
@ -43,7 +43,7 @@ format app_type_mismatch_exception::pp(formatter const & fmt, options const & op
|
||||||
arg_types_fmt += nest(indent, compose(line(), group(format{arg_fmt, space(), colon(), nest(indent, format{line(), arg_type_fmt})})));
|
arg_types_fmt += nest(indent, compose(line(), group(format{arg_fmt, space(), colon(), nest(indent, format{line(), arg_type_fmt})})));
|
||||||
}
|
}
|
||||||
format r;
|
format r;
|
||||||
r += format("type mismatch at application");
|
r += format{format("type mismatch in argument #"), format(m_arg_pos), format(" at application")};
|
||||||
r += nest(indent, compose(line(), app_fmt));
|
r += nest(indent, compose(line(), app_fmt));
|
||||||
r += compose(line(), format("Function type:"));
|
r += compose(line(), format("Function type:"));
|
||||||
r += nest(indent, compose(line(), f_type_fmt));
|
r += nest(indent, compose(line(), f_type_fmt));
|
||||||
|
|
|
@ -127,18 +127,21 @@ public:
|
||||||
class app_type_mismatch_exception : public type_checker_exception {
|
class app_type_mismatch_exception : public type_checker_exception {
|
||||||
context m_context;
|
context m_context;
|
||||||
expr m_app;
|
expr m_app;
|
||||||
|
unsigned m_arg_pos;
|
||||||
std::vector<expr> m_arg_types;
|
std::vector<expr> m_arg_types;
|
||||||
public:
|
public:
|
||||||
app_type_mismatch_exception(ro_environment const & env, context const & ctx, expr const & app, unsigned num, expr const * arg_types):
|
app_type_mismatch_exception(ro_environment const & env, context const & ctx, expr const & app, unsigned arg_pos,
|
||||||
type_checker_exception(env), m_context(ctx), m_app(app), m_arg_types(arg_types, arg_types+num) {}
|
unsigned num, expr const * arg_types):
|
||||||
|
type_checker_exception(env), m_context(ctx), m_app(app), m_arg_pos(arg_pos), m_arg_types(arg_types, arg_types+num) {}
|
||||||
virtual ~app_type_mismatch_exception() {}
|
virtual ~app_type_mismatch_exception() {}
|
||||||
context const & get_context() const { return m_context; }
|
context const & get_context() const { return m_context; }
|
||||||
expr const & get_application() const { return m_app; }
|
expr const & get_application() const { return m_app; }
|
||||||
virtual optional<expr> get_main_expr() const { return some_expr(get_application()); }
|
virtual optional<expr> get_main_expr() const { return some_expr(get_application()); }
|
||||||
|
unsigned get_arg_pos() const { return m_arg_pos; }
|
||||||
std::vector<expr> const & get_arg_types() const { return m_arg_types; }
|
std::vector<expr> const & get_arg_types() const { return m_arg_types; }
|
||||||
virtual char const * what() const noexcept { return "application argument type mismatch"; }
|
virtual char const * what() const noexcept { return "application argument type mismatch"; }
|
||||||
virtual format pp(formatter const & fmt, options const & opts) const;
|
virtual format pp(formatter const & fmt, options const & opts) const;
|
||||||
virtual exception * clone() const { return new app_type_mismatch_exception(m_env, m_context, m_app, m_arg_types.size(), m_arg_types.data()); }
|
virtual exception * clone() const { return new app_type_mismatch_exception(m_env, m_context, m_app, m_arg_pos, m_arg_types.size(), m_arg_types.data()); }
|
||||||
virtual void rethrow() const { throw *this; }
|
virtual void rethrow() const { throw *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -234,7 +234,7 @@ class type_checker::imp {
|
||||||
// thunk for creating justification object if needed
|
// thunk for creating justification object if needed
|
||||||
auto mk_justification = [&](){ return mk_app_type_match_justification(ctx, e, i); };
|
auto mk_justification = [&](){ return mk_app_type_match_justification(ctx, e, i); };
|
||||||
if (!is_convertible(c_t, abst_domain(f_t), ctx, mk_justification))
|
if (!is_convertible(c_t, abst_domain(f_t), ctx, mk_justification))
|
||||||
throw app_type_mismatch_exception(env(), ctx, e, arg_types.size(), arg_types.data());
|
throw app_type_mismatch_exception(env(), ctx, e, i, arg_types.size(), arg_types.data());
|
||||||
f_t = pi_body_at(f_t, c);
|
f_t = pi_body_at(f_t, c);
|
||||||
i++;
|
i++;
|
||||||
if (i == num)
|
if (i == num)
|
||||||
|
|
|
@ -10,7 +10,7 @@ ex2.lean:8:0: error: invalid object declaration, environment already has an obje
|
||||||
Assumed: b
|
Assumed: b
|
||||||
and a b
|
and a b
|
||||||
Assumed: A
|
Assumed: A
|
||||||
ex2.lean:12:8: error: type mismatch at application
|
ex2.lean:12:8: error: type mismatch in argument #2 at application
|
||||||
and a A
|
and a A
|
||||||
Function type:
|
Function type:
|
||||||
Bool -> Bool -> Bool
|
Bool -> Bool -> Bool
|
||||||
|
|
|
@ -7,7 +7,7 @@ kernel_ex1.lean:3:14: error: type expected, got
|
||||||
kernel_ex1.lean:4:6: error: function expected at
|
kernel_ex1.lean:4:6: error: function expected at
|
||||||
a a
|
a a
|
||||||
Assumed: f
|
Assumed: f
|
||||||
kernel_ex1.lean:6:6: error: type mismatch at application
|
kernel_ex1.lean:6:6: error: type mismatch in argument #1 at application
|
||||||
f (λ x : N, x)
|
f (λ x : N, x)
|
||||||
Function type:
|
Function type:
|
||||||
N → N
|
N → N
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
Assumed: N
|
Assumed: N
|
||||||
Assumed: g
|
Assumed: g
|
||||||
Assumed: a
|
Assumed: a
|
||||||
tst9.lean:5:6: error: type mismatch at application
|
tst9.lean:5:6: error: type mismatch in argument #1 at application
|
||||||
g ⊤ (f ?M::0 a a)
|
g ⊤ (f ?M::0 a a)
|
||||||
Function type:
|
Function type:
|
||||||
N → N → Bool
|
N → N → Bool
|
||||||
|
|
Loading…
Reference in a new issue