Fix reversed current/expected type
Fix some reversed type of arm pattern and type of search pattern in error message.
This commit is contained in:
parent
061a223723
commit
35baf5b202
5 changed files with 19 additions and 14 deletions
|
@ -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
|
// check that the type of the value being matched is a subtype
|
||||||
// of the type of the pattern:
|
// of the type of the pattern:
|
||||||
let pat_ty = fcx.node_ty(pat.id);
|
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.
|
// Get the expected types of the arguments.
|
||||||
arg_types = {
|
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
|
// Check that the type of the value being matched is a subtype of
|
||||||
// the type of the pattern.
|
// the type of the pattern.
|
||||||
let pat_ty = fcx.node_ty(pat.id);
|
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.
|
// Get the expected types of the arguments.
|
||||||
let class_fields = ty::struct_fields(
|
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(
|
tcx.sess.span_fatal(
|
||||||
pat.span,
|
pat.span,
|
||||||
fmt!("mismatched types: expected enum or structure but \
|
fmt!("mismatched types: expected `%s` but found enum or \
|
||||||
found `%s`",
|
structure",
|
||||||
fcx.infcx().ty_to_str(expected)));
|
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
|
// Requires that the two types unify, and prints an error message if they
|
||||||
// don't.
|
// don't.
|
||||||
pub fn suptype(fcx: @mut FnCtxt, sp: span, expected: ty::t, actual: ty::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) })
|
|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,
|
pub fn suptype_with_fn(fcx: @mut FnCtxt,
|
||||||
sp: span,
|
sp: span, b_is_expected: bool,
|
||||||
expected: ty::t, actual: ty::t,
|
ty_a: ty::t, ty_b: ty::t,
|
||||||
handle_err: fn(span, ty::t, ty::t, &ty::type_err)) {
|
handle_err: fn(span, ty::t, ty::t, &ty::type_err)) {
|
||||||
// n.b.: order of actual, expected is reversed
|
// n.b.: order of actual, expected is reversed
|
||||||
match infer::mk_subty(fcx.infcx(), false, sp,
|
match infer::mk_subty(fcx.infcx(), b_is_expected, sp,
|
||||||
actual, expected) {
|
ty_b, ty_a) {
|
||||||
result::Ok(()) => { /* ok */ }
|
result::Ok(()) => { /* ok */ }
|
||||||
result::Err(ref err) => {
|
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);
|
let tail_expr_ty = fcx.expr_ty(tail_expr);
|
||||||
// Special case: we print a special error if there appears
|
// Special case: we print a special error if there appears
|
||||||
// to be do-block/for-loop confusion
|
// 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| {
|
|sp, e, a, s| {
|
||||||
fcx.report_mismatched_return_types(sp, e, a, s) });
|
fcx.report_mismatched_return_types(sp, e, a, s) });
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match None {
|
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 }
|
struct S { a: int }
|
||||||
enum E { C(int) }
|
enum E { C(int) }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match S { a: 1 } {
|
match S { a: 1 } {
|
||||||
C(_) => (),
|
C(_) => (), //~ ERROR mismatched types: expected `S` but found `E`
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue