@@ -195,7 +195,9 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::Path,
195195 Some ( ref subpats) => subpats_len = subpats. len ( )
196196 }
197197
198- if arg_len > 0 u {
198+ let mut error_happened = false ;
199+
200+ if arg_len > 0 {
199201 // N-ary variant.
200202 if arg_len != subpats_len {
201203 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,
205207 kind_name,
206208 arg_len,
207209 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 ;
210212 }
211213
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+ }
215219 }
216220 }
217- } else if subpats_len > 0u {
218- tcx.sess.span_fatal
221+ } else if subpats_len > 0 {
222+ tcx.sess.span_err
219223 (pat.span, fmt!(" this pattern has %u field%s, but the \
220224 corresponding %s has no fields",
221225 subpats_len,
222226 if subpats_len == 1u { ~" " }
223227 else { ~" s" },
224228 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+ }
225240 }
226241}
227242
@@ -446,6 +461,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
446461 ast::pat_struct(path, ref fields, etc) => {
447462 // Grab the class data that we care about.
448463 let structure = structure_of(fcx, pat.span, expected);
464+ let mut error_happened = false;
449465 match structure {
450466 ty::ty_struct(cid, ref substs) => {
451467 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) {
457473 substs);
458474 }
459475 _ => {
460- // XXX: This should not be fatal.
461- tcx.sess.span_fatal(pat.span,
476+ tcx.sess.span_err(pat.span,
462477 fmt!(" mismatched types: expected `%s` \
463478 but found struct ",
464479 fcx.infcx().ty_to_str(expected)));
480+ error_happened = true;
465481 }
466482 }
467483
468484 // 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+ }
470491 }
471492 ast::pat_tup(ref elts) => {
472493 let s = structure_of(fcx, pat.span, expected);
0 commit comments