1
Fork 0

Correct error message for argument mode mismatch

If you use a function expecting an alias argument in a context that
expects a function expecting a value argument, or vice versa, the
previous error message complained that the number of arguments was
wrong. Fixed the error message to be accurate.
This commit is contained in:
Tim Chevalier 2011-06-23 11:32:37 -07:00
parent 5bd65de289
commit 3cf00c1577
3 changed files with 35 additions and 9 deletions

View file

@ -22,6 +22,7 @@ import middle::metadata;
import util::common::*;
import util::data::interner;
import pretty::ppaux::ty_to_str;
import pretty::ppaux::mode_str_1;
export node_id_to_monotype;
@ -292,6 +293,7 @@ tag type_err {
terr_meth_count;
terr_obj_meths(ast::ident, ast::ident);
terr_arg_count;
terr_mode_mismatch(mode, mode);
}
type ty_param_count_and_ty = tup(uint, t);
@ -1984,9 +1986,8 @@ mod unify {
auto result_mode;
if (expected_input.mode != actual_input.mode) {
// FIXME this is the wrong error
ret fn_common_res_err(ures_err(terr_arg_count));
ret fn_common_res_err(ures_err(terr_mode_mismatch(
expected_input.mode, actual_input.mode)));
} else { result_mode = expected_input.mode; }
auto result = unify_step(cx, expected_input.ty, actual_input.ty);
alt (result) {
@ -2584,6 +2585,11 @@ fn type_err_to_str(&ty::type_err err) -> str {
ret "expected an obj with method '" + e_meth +
"' but found one with method '" + a_meth + "'";
}
case (terr_mode_mismatch(?e_mode, ?a_mode)) {
ret "expected argument mode " + mode_str_1(e_mode) + " but found "
+ mode_str_1(a_mode);
fail;
}
}
}

View file

@ -5,6 +5,7 @@ import std::str;
import std::option;
import std::option::none;
import std::option::some;
import middle::ty;
import middle::ty::*;
import front::lexer;
import front::ast;
@ -18,15 +19,25 @@ import util::common::istr;
import util::common::uistr;
import util::common::ty_mach_to_str;
fn mode_str(&ty::mode m) -> str {
alt (m) {
case (mo_val) { "" }
case (mo_alias(false)) { "&" }
case (mo_alias(true)) { "&mutable " }
}
}
fn mode_str_1(&ty::mode m) -> str {
alt (m) {
case (mo_val) { "val" }
case (_) { mode_str(m) }
}
}
fn ty_to_str(&ctxt cx, &t typ) -> str {
fn fn_input_to_str(&ctxt cx, &rec(middle::ty::mode mode, t ty) input) ->
str {
auto s =
alt (input.mode) {
case (mo_val) { "" }
case (mo_alias(false)) { "&" }
case (mo_alias(true)) { "&mutable " }
};
auto s = mode_str(input.mode);
ret s + ty_to_str(cx, input.ty);
}
fn fn_to_str(&ctxt cx, ast::proto proto, option::t[ast::ident] ident,

View file

@ -0,0 +1,9 @@
// error-pattern:expected argument mode
use std;
import std::vec::map;
fn main() {
fn f(uint i) -> bool { true }
auto a = map(f, [5u]);
}