From 8015e6d52b7eeea47f9e61c6ac42487935474ca4 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 22 Feb 2012 13:34:43 +0100 Subject: [PATCH] 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. --- src/comp/middle/typeck.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 2ffa191b6d8e..ed9eb3c35600 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1146,8 +1146,10 @@ mod writeback { typ) { fix_ok(new_type) { ret some(new_type); } fix_err(vid) { - fcx.ccx.tcx.sess.span_err(sp, "cannot determine a type \ - for this expression"); + if !fcx.ccx.tcx.sess.has_errors() { + fcx.ccx.tcx.sess.span_err(sp, "cannot determine a type \ + for this expression"); + } ret none; } } @@ -2546,7 +2548,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, field, ty_to_str(tcx, t_err)]; tcx.sess.span_err(expr.span, msg); // NB: Adding a bogus type to allow typechecking to continue - write_ty(tcx, id, ty::mk_nil(tcx)); + write_ty(tcx, id, next_ty_var(fcx)); } } }