Skip to content

Commit 0857d22

Browse files
committed
rustc: Print out a real error message on unresolved types. Puts out burning tinderbox.
1 parent ddec6b5 commit 0857d22

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

src/comp/middle/ty.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,42 +2537,47 @@ mod unify {
25372537
// Fixups and substitutions
25382538

25392539
fn fixup_vars(ty_ctxt tcx, @var_bindings vb, t typ) -> fixup_result {
2540-
fn subst_vars(ty_ctxt tcx, @var_bindings vb, t typ) -> t {
2540+
fn subst_vars(ty_ctxt tcx, @var_bindings vb,
2541+
@mutable option::t[int] unresolved, t typ) -> t {
25412542
alt (struct(tcx, typ)) {
25422543
case (ty::ty_var(?vid)) {
2544+
if ((vid as uint) >= ufind::set_count(vb.sets)) {
2545+
*unresolved = some[int](vid);
2546+
ret typ;
2547+
}
2548+
25432549
auto root_id = ufind::find(vb.sets, vid as uint);
25442550
alt (smallintmap::find[t](vb.types, root_id)) {
25452551
case (none[t]) {
2546-
log_err "unresolved type variable";
2547-
fail;
2552+
*unresolved = some[int](vid);
2553+
ret typ;
25482554
}
25492555
case (some[t](?rt)) {
2550-
ret fold_ty(tcx, bind subst_vars(tcx, vb, _), rt);
2556+
ret fold_ty(tcx,
2557+
bind subst_vars(tcx, vb, unresolved, _), rt);
25512558
}
25522559
}
25532560
}
25542561
case (_) { ret typ; }
25552562
}
25562563
}
25572564

2558-
// FIXME: Report errors better.
2559-
ret fix_ok(fold_ty(tcx, bind subst_vars(tcx, vb, _), typ));
2565+
auto unresolved = @mutable none[int];
2566+
auto rty = fold_ty(tcx, bind subst_vars(tcx, vb, unresolved, _), typ);
2567+
2568+
auto ur = *unresolved;
2569+
alt (ur) {
2570+
case (none[int]) { ret fix_ok(rty); }
2571+
case (some[int](?var_id)) { ret fix_err(var_id); }
2572+
}
25602573
}
25612574

2562-
fn resolve_type_var(&ty_ctxt tcx, &@var_bindings vb, int vid) -> t {
2575+
fn resolve_type_var(&ty_ctxt tcx, &@var_bindings vb, int vid)
2576+
-> fixup_result {
25632577
auto root_id = ufind::find(vb.sets, vid as uint);
25642578
alt (smallintmap::find[t](vb.types, root_id)) {
2565-
case (none[t]) { ret mk_var(tcx, vid); }
2566-
case (some[t](?rt)) {
2567-
alt (fixup_vars(tcx, vb, rt)) {
2568-
case (fix_ok(?rty)) { ret rty; }
2569-
case (fix_err(_)) {
2570-
// TODO: antisocial
2571-
log_err "failed to resolve type var";
2572-
fail;
2573-
}
2574-
}
2575-
}
2579+
case (none[t]) { ret fix_ok(mk_var(tcx, vid)); }
2580+
case (some[t](?rt)) { ret fixup_vars(tcx, vb, rt); }
25762581
}
25772582
}
25782583
}

src/comp/middle/typeck.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,11 +1387,8 @@ mod writeback {
13871387
alt (ty::unify::fixup_vars(fcx.ccx.tcx, fcx.var_bindings, typ)) {
13881388
case (fix_ok(?new_type)) { ret new_type; }
13891389
case (fix_err(?vid)) {
1390-
// TODO: We should try to do a variable ID -> local lookup if
1391-
// we can and display this in terms of the local that had an
1392-
// incomplete type.
1393-
fcx.ccx.tcx.sess.span_err(sp, #fmt(
1394-
"cannot determine type of variable ID `%d`", vid));
1390+
fcx.ccx.tcx.sess.span_err(sp,
1391+
"cannot determine a type for this expression");
13951392
}
13961393
}
13971394
}
@@ -1434,11 +1431,19 @@ mod writeback {
14341431
fn visit_decl_pre(@fn_ctxt fcx, &@ast::decl d) {
14351432
alt (d.node) {
14361433
case (ast::decl_local(?l)) {
1437-
// FIXME: Report errors better.
14381434
auto var_id = fcx.locals.get(l.id);
1439-
auto lty = ty::unify::resolve_type_var(fcx.ccx.tcx,
1435+
auto fix_rslt = ty::unify::resolve_type_var(fcx.ccx.tcx,
14401436
fcx.var_bindings, var_id);
1441-
write::ty_only(fcx.ccx.tcx, l.ann.id, lty);
1437+
alt (fix_rslt) {
1438+
case (fix_ok(?lty)) {
1439+
write::ty_only(fcx.ccx.tcx, l.ann.id, lty);
1440+
}
1441+
case (fix_err(_)) {
1442+
fcx.ccx.tcx.sess.span_err(d.span,
1443+
"cannot determine a type for this local " +
1444+
"variable");
1445+
}
1446+
}
14421447
}
14431448
case (_) { /* no-op */ }
14441449
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// xfail-stage0
22

3-
// error-pattern:Ambiguous type
3+
// error-pattern:cannot determine a type
44
fn main() -> () {
55
auto foo = [];
66
}

0 commit comments

Comments
 (0)