Skip to content

Commit b6fc86a

Browse files
committed
Sane error message for self-call in non-obj context. Closes #707.
1 parent 46b0aa5 commit b6fc86a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/comp/middle/typeck.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
20922092
}
20932093
case (ast::expr_self_method(?ident)) {
20942094
auto t = ty::mk_nil(fcx.ccx.tcx);
2095-
let ty::t this_obj_ty;
2095+
let ty::t this_obj_ty = ty::mk_nil(fcx.ccx.tcx);
20962096
let option::t[obj_info] this_obj_info = get_obj_info(fcx.ccx);
20972097
alt (this_obj_info) {
20982098
case (
@@ -2106,7 +2106,12 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
21062106
ty::lookup_item_type(fcx.ccx.tcx,
21072107
local_def(obj_info.this_obj))._1;
21082108
}
2109-
case (none) { fail; }
2109+
case (none) {
2110+
// Shouldn't happen.
2111+
fcx.ccx.tcx.sess.span_err(expr.span,
2112+
"self-call in non-object \
2113+
context");
2114+
}
21102115
}
21112116
// Grab this method's type out of the current object type.
21122117

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//xfail-stage0
2+
3+
// error-pattern:self-call in non-object context
4+
5+
// Fix for issue #707.
6+
fn main() {
7+
8+
fn foo() -> int {
9+
ret 3();
10+
}
11+
12+
self.foo();
13+
14+
}

0 commit comments

Comments
 (0)