Merge remote-tracking branch 'remotes/origin/incoming' into incoming
This commit is contained in:
commit
7f5d4cbda0
@ -103,7 +103,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
|
||||
// check that the type of the value being matched is a subtype
|
||||
// of the type of the pattern:
|
||||
let pat_ty = fcx.node_ty(pat.id);
|
||||
demand::suptype(fcx, pat.span, pat_ty, expected);
|
||||
demand::subtype(fcx, pat.span, expected, pat_ty);
|
||||
|
||||
// Get the expected types of the arguments.
|
||||
arg_types = {
|
||||
@ -142,7 +142,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
|
||||
// Check that the type of the value being matched is a subtype of
|
||||
// the type of the pattern.
|
||||
let pat_ty = fcx.node_ty(pat.id);
|
||||
demand::suptype(fcx, pat.span, pat_ty, expected);
|
||||
demand::subtype(fcx, pat.span, expected, pat_ty);
|
||||
|
||||
// Get the expected types of the arguments.
|
||||
let class_fields = ty::struct_fields(
|
||||
@ -154,8 +154,8 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
|
||||
_ => {
|
||||
tcx.sess.span_fatal(
|
||||
pat.span,
|
||||
fmt!("mismatched types: expected enum or structure but \
|
||||
found `%s`",
|
||||
fmt!("mismatched types: expected `%s` but found enum or \
|
||||
structure",
|
||||
fcx.infcx().ty_to_str(expected)));
|
||||
}
|
||||
}
|
||||
|
@ -21,20 +21,25 @@ use syntax::codemap::span;
|
||||
// Requires that the two types unify, and prints an error message if they
|
||||
// don't.
|
||||
pub fn suptype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::t) {
|
||||
suptype_with_fn(fcx, sp, expected, actual,
|
||||
suptype_with_fn(fcx, sp, false, expected, actual,
|
||||
|sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) })
|
||||
}
|
||||
|
||||
pub fn subtype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::t) {
|
||||
suptype_with_fn(fcx, sp, true, actual, expected,
|
||||
|sp, a, e, s| { fcx.report_mismatched_types(sp, e, a, s) })
|
||||
}
|
||||
|
||||
pub fn suptype_with_fn(fcx: @mut FnCtxt,
|
||||
sp: span,
|
||||
expected: ty::t, actual: ty::t,
|
||||
sp: span, b_is_expected: bool,
|
||||
ty_a: ty::t, ty_b: ty::t,
|
||||
handle_err: fn(span, ty::t, ty::t, &ty::type_err)) {
|
||||
// n.b.: order of actual, expected is reversed
|
||||
match infer::mk_subty(fcx.infcx(), false, sp,
|
||||
actual, expected) {
|
||||
match infer::mk_subty(fcx.infcx(), b_is_expected, sp,
|
||||
ty_b, ty_a) {
|
||||
result::Ok(()) => { /* ok */ }
|
||||
result::Err(ref err) => {
|
||||
handle_err(sp, expected, actual, err);
|
||||
handle_err(sp, ty_a, ty_b, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +355,8 @@ pub fn check_fn(ccx: @mut CrateCtxt,
|
||||
let tail_expr_ty = fcx.expr_ty(tail_expr);
|
||||
// Special case: we print a special error if there appears
|
||||
// to be do-block/for-loop confusion
|
||||
demand::suptype_with_fn(fcx, tail_expr.span, fcx.ret_ty, tail_expr_ty,
|
||||
demand::suptype_with_fn(fcx, tail_expr.span, false,
|
||||
fcx.ret_ty, tail_expr_ty,
|
||||
|sp, e, a, s| {
|
||||
fcx.report_mismatched_return_types(sp, e, a, s) });
|
||||
}
|
||||
|
@ -10,6 +10,6 @@
|
||||
|
||||
fn main() {
|
||||
match None {
|
||||
Err(_) => () //~ ERROR expected `core::result
|
||||
Err(_) => () //~ ERROR mismatched types: expected `core::option::Option<<V1>>` but found `core::result::Result<<V2>,<V3>>`
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
// error-pattern: mismatched types
|
||||
|
||||
struct S { a: int }
|
||||
enum E { C(int) }
|
||||
|
||||
fn main() {
|
||||
match S { a: 1 } {
|
||||
C(_) => (),
|
||||
C(_) => (), //~ ERROR mismatched types: expected `S` but found `E`
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user