Skip to content

Commit

Permalink
Sane error message for self-call in non-obj context. Closes #707.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuper committed Jul 18, 2011
1 parent 46b0aa5 commit b6fc86a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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.

Expand Down
14 changes: 14 additions & 0 deletions src/test/compile-fail/self-call-non-obj.rs
Original file line number Diff line number Diff line change
@@ -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();

}

0 comments on commit b6fc86a

Please sign in to comment.