fix(kernel/type_checker): Pi with metavariables case

The type checker (and type inferer) were not handling correctly Pi expressions where the type universe cannot be established due to the occurrence of metavariables. In this case, a max-constraint is created. The problem is that the domain and body of the Pi are in different contexts. The constrain generated before this commit was incorrect, it could contain a free variable. This commit fix the issue by using the context of the body, and lifting the free variables in the domain by 1.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-12-06 13:07:33 -08:00
parent fa03ae2a26
commit d79a626523
2 changed files with 4 additions and 4 deletions

View file

@ -173,9 +173,9 @@ class type_checker::imp {
case expr_kind::Pi: { case expr_kind::Pi: {
expr t1 = check_type(infer_type_core(abst_domain(e), ctx), abst_domain(e), ctx); expr t1 = check_type(infer_type_core(abst_domain(e), ctx), abst_domain(e), ctx);
expr t2; expr t2;
context new_ctx = extend(ctx, abst_name(e), abst_domain(e));
{ {
cache::mk_scope sc(m_cache); cache::mk_scope sc(m_cache);
context new_ctx = extend(ctx, abst_name(e), abst_domain(e));
t2 = check_type(infer_type_core(abst_body(e), new_ctx), abst_body(e), new_ctx); t2 = check_type(infer_type_core(abst_body(e), new_ctx), abst_body(e), new_ctx);
} }
if (is_type(t1) && is_type(t2)) { if (is_type(t1) && is_type(t2)) {
@ -184,7 +184,7 @@ class type_checker::imp {
lean_assert(m_uc); lean_assert(m_uc);
justification jst = mk_max_type_justification(ctx, e); justification jst = mk_max_type_justification(ctx, e);
r = m_menv->mk_metavar(ctx); r = m_menv->mk_metavar(ctx);
m_uc->push_back(mk_max_constraint(ctx, t1, t2, r, jst)); m_uc->push_back(mk_max_constraint(new_ctx, lift_free_vars(t1, 0, 1), t2, r, jst));
} }
break; break;
} }

View file

@ -181,9 +181,9 @@ class type_inferer::imp {
case expr_kind::Pi: { case expr_kind::Pi: {
expr t1 = check_type(infer_type(abst_domain(e), ctx), abst_domain(e), ctx); expr t1 = check_type(infer_type(abst_domain(e), ctx), abst_domain(e), ctx);
expr t2; expr t2;
context new_ctx = extend(ctx, abst_name(e), abst_domain(e));
{ {
cache::mk_scope sc(m_cache); cache::mk_scope sc(m_cache);
context new_ctx = extend(ctx, abst_name(e), abst_domain(e));
t2 = check_type(infer_type(abst_body(e), new_ctx), abst_body(e), new_ctx); t2 = check_type(infer_type(abst_body(e), new_ctx), abst_body(e), new_ctx);
} }
if (is_type(t1) && is_type(t2)) { if (is_type(t1) && is_type(t2)) {
@ -192,7 +192,7 @@ class type_inferer::imp {
lean_assert(m_uc); lean_assert(m_uc);
justification jst = mk_max_type_justification(ctx, e); justification jst = mk_max_type_justification(ctx, e);
r = m_menv->mk_metavar(ctx); r = m_menv->mk_metavar(ctx);
m_uc->push_back(mk_max_constraint(ctx, t1, t2, r, jst)); m_uc->push_back(mk_max_constraint(new_ctx, lift_free_vars(t1, 0, 1), t2, r, jst));
} }
break; break;
} }