Skip to content

Commit 04b239f

Browse files
committed
Use more precise spans in error messages for bad FRU exprs
The type error message for an expression using FRU where a field expression had the wrong type was using the span for the entire expression. Fixed it to use the span for the individual field. Closes #628.
1 parent 6b86dcd commit 04b239f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/comp/middle/typeck.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ast::mutability;
44
import ast::local_def;
55
import ast::path_to_str;
66
import ast::respan;
7+
import ast::spanned;
78
import syntax::walk;
89
import metadata::csearch;
910
import driver::session;
@@ -2177,16 +2178,21 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
21772178
case (none) {/* no-op */ }
21782179
case (some(?b_0)) { check_expr(fcx, b_0); }
21792180
}
2180-
let field[] fields_t = ~[];
2181+
let (spanned[field])[] fields_t = ~[];
21812182
for (ast::field f in fields) {
21822183
check_expr(fcx, f.node.expr);
21832184
auto expr_t = expr_ty(fcx.ccx.tcx, f.node.expr);
21842185
auto expr_mt = rec(ty=expr_t, mut=f.node.mut);
2185-
fields_t += ~[rec(ident=f.node.ident, mt=expr_mt)];
2186+
// for the most precise error message,
2187+
// should be f.node.expr.span, not f.span
2188+
fields_t += ~[respan(f.node.expr.span,
2189+
rec(ident=f.node.ident, mt=expr_mt))];
21862190
}
21872191
alt (base) {
21882192
case (none) {
2189-
auto typ = ty::mk_rec(fcx.ccx.tcx, fields_t);
2193+
fn get_node(&spanned[field] f) -> field { f.node }
2194+
auto typ = ty::mk_rec(fcx.ccx.tcx,
2195+
ivec::map(get_node, fields_t));
21902196
write::ty_only_fixup(fcx, id, typ);
21912197
}
21922198
case (some(?bexpr)) {
@@ -2202,20 +2208,20 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
22022208
}
22032209
}
22042210
write::ty_only_fixup(fcx, id, bexpr_t);
2205-
for (ty::field f in fields_t) {
2211+
for (spanned[ty::field] f in fields_t) {
22062212
auto found = false;
22072213
for (ty::field bf in base_fields) {
2208-
if (str::eq(f.ident, bf.ident)) {
2209-
demand::simple(fcx, expr.span, bf.mt.ty,
2210-
f.mt.ty);
2214+
if (str::eq(f.node.ident, bf.ident)) {
2215+
demand::simple(fcx, f.span, bf.mt.ty,
2216+
f.node.mt.ty);
22112217
found = true;
22122218
}
22132219
}
22142220
if (!found) {
2215-
fcx.ccx.tcx.sess.span_fatal(expr.span,
2221+
fcx.ccx.tcx.sess.span_fatal(f.span,
22162222
"unknown field in \
22172223
record update: "
2218-
+ f.ident);
2224+
+ f.node.ident);
22192225
}
22202226
}
22212227
}

0 commit comments

Comments
 (0)