Skip to content

Commit 8015e6d

Browse files
committed
Return a new type var instead of nil when failing to typecheck a field
The previous solution was usually causing a second spurious error message.
1 parent ffd50b9 commit 8015e6d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/comp/middle/typeck.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,10 @@ mod writeback {
11461146
typ) {
11471147
fix_ok(new_type) { ret some(new_type); }
11481148
fix_err(vid) {
1149-
fcx.ccx.tcx.sess.span_err(sp, "cannot determine a type \
1150-
for this expression");
1149+
if !fcx.ccx.tcx.sess.has_errors() {
1150+
fcx.ccx.tcx.sess.span_err(sp, "cannot determine a type \
1151+
for this expression");
1152+
}
11511153
ret none;
11521154
}
11531155
}
@@ -2546,7 +2548,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
25462548
field, ty_to_str(tcx, t_err)];
25472549
tcx.sess.span_err(expr.span, msg);
25482550
// NB: Adding a bogus type to allow typechecking to continue
2549-
write_ty(tcx, id, ty::mk_nil(tcx));
2551+
write_ty(tcx, id, next_ty_var(fcx));
25502552
}
25512553
}
25522554
}

0 commit comments

Comments
 (0)