@@ -195,7 +195,9 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::Path,
195
195
Some ( ref subpats) => subpats_len = subpats. len ( )
196
196
}
197
197
198
- if arg_len > 0 u {
198
+ let mut error_happened = false ;
199
+
200
+ if arg_len > 0 {
199
201
// N-ary variant.
200
202
if arg_len != subpats_len {
201
203
let s = fmt!( "this pattern has %u field%s, but the corresponding \
@@ -205,23 +207,36 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::Path,
205
207
kind_name,
206
208
arg_len,
207
209
if arg_len == 1u { ~" " } else { ~" s" });
208
- // XXX: This should not be fatal.
209
- tcx.sess.span_fatal(pat.span, s) ;
210
+ tcx.sess.span_err(pat.span, s);
211
+ error_happened = true ;
210
212
}
211
213
212
- for subpats.each |pats| {
213
- for vec::each2(*pats, arg_types) |subpat, arg_ty| {
214
- check_pat(pcx, *subpat, *arg_ty);
214
+ if !error_happened {
215
+ for subpats.each |pats| {
216
+ for vec::each2(*pats, arg_types) |subpat, arg_ty| {
217
+ check_pat(pcx, *subpat, *arg_ty);
218
+ }
215
219
}
216
220
}
217
- } else if subpats_len > 0u {
218
- tcx.sess.span_fatal
221
+ } else if subpats_len > 0 {
222
+ tcx.sess.span_err
219
223
(pat.span, fmt!(" this pattern has %u field%s, but the \
220
224
corresponding %s has no fields",
221
225
subpats_len,
222
226
if subpats_len == 1u { ~" " }
223
227
else { ~" s" },
224
228
kind_name));
229
+ error_happened = true;
230
+ }
231
+
232
+ if error_happened {
233
+ let tcx = pcx.fcx.ccx.tcx;
234
+
235
+ for subpats.each |pats| {
236
+ for pats.each |pat| {
237
+ check_pat(pcx, *pat, ty::mk_err(tcx));
238
+ }
239
+ }
225
240
}
226
241
}
227
242
@@ -446,6 +461,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
446
461
ast::pat_struct(path, ref fields, etc) => {
447
462
// Grab the class data that we care about.
448
463
let structure = structure_of(fcx, pat.span, expected);
464
+ let mut error_happened = false;
449
465
match structure {
450
466
ty::ty_struct(cid, ref substs) => {
451
467
check_struct_pat(pcx, pat.id, pat.span, expected, path,
@@ -457,16 +473,21 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
457
473
substs);
458
474
}
459
475
_ => {
460
- // XXX: This should not be fatal.
461
- tcx.sess.span_fatal(pat.span,
476
+ tcx.sess.span_err(pat.span,
462
477
fmt!(" mismatched types: expected `%s` \
463
478
but found struct ",
464
479
fcx.infcx().ty_to_str(expected)));
480
+ error_happened = true;
465
481
}
466
482
}
467
483
468
484
// Finally, write in the type.
469
- fcx.write_ty(pat.id, expected);
485
+ if error_happened {
486
+ fcx.write_error(pat.id);
487
+ }
488
+ else {
489
+ fcx.write_ty(pat.id, expected);
490
+ }
470
491
}
471
492
ast::pat_tup(ref elts) => {
472
493
let s = structure_of(fcx, pat.span, expected);
0 commit comments