Don't create a new inference context for checking pattern ranges.

Ugly fix -- it would be better to refactor and consolidate the various
"make sure these types are the same" fns scattered around typeck.
This commit is contained in:
Lindsey Kuper 2012-06-19 16:53:41 -07:00
parent 3e281439a0
commit 26bd186726
3 changed files with 28 additions and 3 deletions

View file

@ -203,6 +203,23 @@ fn require_same_types(
}
}
fn require_same_types_in_infcx(
infcx: infer::infer_ctxt,
span: span,
t1: ty::t,
t2: ty::t,
msg: fn() -> str) -> bool {
alt infer::compare_tys_in_infcx(infcx, t1, t2) {
result::ok(()) { true }
result::err(terr) {
infcx.tcx.sess.span_err(span, msg() + ": " +
ty::type_err_to_str(infcx.tcx, terr));
false
}
}
}
fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool {
alt ty::get(a.ty).struct {
ty::ty_vec(mt) {

View file

@ -137,9 +137,12 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
check_expr_with(fcx, end, expected);
let b_ty =
fcx.infcx.resolve_type_vars_if_possible(fcx.expr_ty(begin));
if !require_same_types(
tcx, pat.span, b_ty,
fcx.infcx.resolve_type_vars_if_possible(fcx.expr_ty(end)),
let e_ty =
fcx.infcx.resolve_type_vars_if_possible(fcx.expr_ty(end));
#debug["pat_range beginning type: %?", b_ty];
#debug["pat_range ending type: %?", e_ty];
if !require_same_types_in_infcx(
fcx.infcx, pat.span, b_ty, e_ty,
{|| "mismatched types in range" }) {
// no-op
} else if !ty::type_is_numeric(b_ty) {

View file

@ -172,6 +172,7 @@ export resolve_deep_var;
export methods; // for infer_ctxt
export unify_methods; // for infer_ctxt
export compare_tys;
export compare_tys_in_infcx;
export fixup_err, fixup_err_to_str;
export assignment;
export root, to_str;
@ -381,6 +382,10 @@ fn compare_tys(tcx: ty::ctxt, a: ty::t, b: ty::t) -> ures {
mk_eqty(infcx, a, b)
}
fn compare_tys_in_infcx(infcx: infer_ctxt, a: ty::t, b: ty::t) -> ures {
mk_eqty(infcx, a, b)
}
// See comment on the type `resolve_state` below
fn resolve_shallow(cx: infer_ctxt, a: ty::t,
force_vars: force_level) -> fres<ty::t> {