Improve a typechecker error message (wrong type for main())

As per #1903, state what type is expected for main().

Closes #1903
This commit is contained in:
Tim Chevalier 2012-03-11 20:55:19 -07:00
parent fde4c1efbb
commit 664d71f1f0
4 changed files with 8 additions and 7 deletions

View File

@ -3122,10 +3122,11 @@ fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id, main_span: span) {
ok &= num_args == 0u || num_args == 1u &&
arg_is_argv_ty(tcx, inputs[0]);
if !ok {
tcx.sess.span_err(main_span,
"wrong type in main function: found `" +
ty_to_str(tcx, main_t) + "`");
}
tcx.sess.span_err(main_span,
#fmt("Wrong type in main function: found `%s`, \
expecting `native fn([str]) -> ()` or `native fn() -> ()`",
ty_to_str(tcx, main_t)));
}
}
_ {
tcx.sess.span_bug(main_span,

View File

@ -1,3 +1,3 @@
// error-pattern:wrong type in main function
// error-pattern:expecting `native fn([str])
fn main(x: int) { }

View File

@ -1,3 +1,3 @@
fn main() -> char {
//!^ ERROR wrong type in main function: found `native fn() -> char`
//!^ ERROR Wrong type in main function: found `native fn() -> char`
}

View File

@ -1,3 +1,3 @@
fn main(foo: {x: int, y: int}) {
//!^ ERROR wrong type in main function: found `native fn({x: int,y: int})`
//!^ ERROR Wrong type in main function: found `native fn({x: int,y: int})`
}