Sane error message for self-call in non-obj context. Closes #707.

This commit is contained in:
Lindsey Kuper 2011-07-18 15:52:05 -07:00
parent 46b0aa5c5c
commit b6fc86ae5a
2 changed files with 21 additions and 2 deletions

View file

@ -2092,7 +2092,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
}
case (ast::expr_self_method(?ident)) {
auto t = ty::mk_nil(fcx.ccx.tcx);
let ty::t this_obj_ty;
let ty::t this_obj_ty = ty::mk_nil(fcx.ccx.tcx);
let option::t[obj_info] this_obj_info = get_obj_info(fcx.ccx);
alt (this_obj_info) {
case (
@ -2106,7 +2106,12 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
ty::lookup_item_type(fcx.ccx.tcx,
local_def(obj_info.this_obj))._1;
}
case (none) { fail; }
case (none) {
// Shouldn't happen.
fcx.ccx.tcx.sess.span_err(expr.span,
"self-call in non-object \
context");
}
}
// Grab this method's type out of the current object type.

View file

@ -0,0 +1,14 @@
//xfail-stage0
// error-pattern:self-call in non-object context
// Fix for issue #707.
fn main() {
fn foo() -> int {
ret 3();
}
self.foo();
}