diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 4cb3a219a880..a8450c30ee64 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -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. diff --git a/src/test/compile-fail/self-call-non-obj.rs b/src/test/compile-fail/self-call-non-obj.rs new file mode 100644 index 000000000000..816c8ad698f3 --- /dev/null +++ b/src/test/compile-fail/self-call-non-obj.rs @@ -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(); + +}