From c9c1d860f14d2d422106d21a30beb2ea237d9de3 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 9 Jun 2011 17:23:15 -0700 Subject: [PATCH] rustc: Report type errors in terms of the actual types involved, not type variables --- src/comp/middle/typeck.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 637e4c05669..98bb1f9de30 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -896,6 +896,14 @@ fn count_boxes(&@fn_ctxt fcx, &span sp, &ty::t t) -> uint { } +fn resolve_type_vars_if_possible(&@fn_ctxt fcx, ty::t typ) -> ty::t { + alt (ty::unify::fixup_vars(fcx.ccx.tcx, fcx.var_bindings, typ)) { + case (fix_ok(?new_type)) { ret new_type; } + case (fix_err(_)) { ret typ; } + } +} + + // Demands - procedures that require that two types unify and emit an error // message if they don't. @@ -956,10 +964,13 @@ fn full(&@fn_ctxt fcx, &span sp, &ty::t expected, &ty::t actual, } case (ures_err(?err)) { + auto e_err = resolve_type_vars_if_possible(fcx, expected_1); + auto a_err = resolve_type_vars_if_possible(fcx, actual_1); + fcx.ccx.tcx.sess.span_err (sp, "mismatched types: expected " - + ty_to_str(fcx.ccx.tcx, expected_1) + " but found " - + ty_to_str(fcx.ccx.tcx, actual_1) + " (" + + ty_to_str(fcx.ccx.tcx, e_err) + " but found " + + ty_to_str(fcx.ccx.tcx, a_err) + " (" + ty::type_err_to_str(err) + ")"); // TODO: In the future, try returning "expected", reporting