Beginnings of support for magical self prefix; nothing profound happening yet.
This commit is contained in:
parent
f6490a6f03
commit
55fbed3d8d
@ -252,6 +252,7 @@ tag expr_ {
|
||||
expr_tup(vec[elt], ann);
|
||||
expr_rec(vec[field], option.t[@expr], ann);
|
||||
expr_call(@expr, vec[@expr], ann);
|
||||
expr_call_self(@expr, vec[@expr], ann);
|
||||
expr_bind(@expr, vec[option.t[@expr]], ann);
|
||||
expr_spawn(spawn_dom, option.t[str], @expr, vec[@expr], ann);
|
||||
expr_binary(binop, @expr, @expr, ann);
|
||||
|
@ -169,6 +169,7 @@ impure fn new_reader(io.reader rdr, str filename) -> reader
|
||||
keywords.insert("any", token.ANY);
|
||||
|
||||
keywords.insert("obj", token.OBJ);
|
||||
keywords.insert("self", token.SELF);
|
||||
|
||||
keywords.insert("port", token.PORT);
|
||||
keywords.insert("chan", token.CHAN);
|
||||
|
@ -883,6 +883,20 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
|
||||
ex = ast.expr_chan(e, ast.ann_none);
|
||||
}
|
||||
|
||||
case (token.SELF) {
|
||||
p.bump();
|
||||
expect(p, token.DOT);
|
||||
// The rest is a call expression.
|
||||
auto e = parse_bottom_expr(p);
|
||||
auto pf = parse_expr;
|
||||
auto es = parse_seq[@ast.expr](token.LPAREN,
|
||||
token.RPAREN,
|
||||
some(token.COMMA),
|
||||
pf, p);
|
||||
hi = es.span;
|
||||
auto ex = ast.expr_call_self(e, es.node, ast.ann_none);
|
||||
}
|
||||
|
||||
case (_) {
|
||||
auto lit = parse_lit(p);
|
||||
hi = lit.span;
|
||||
@ -1646,6 +1660,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
|
||||
case (ast.expr_tup(_,_)) { ret true; }
|
||||
case (ast.expr_rec(_,_,_)) { ret true; }
|
||||
case (ast.expr_call(_,_,_)) { ret true; }
|
||||
case (ast.expr_call_self(_,_,_)){ ret true; }
|
||||
case (ast.expr_binary(_,_,_,_)) { ret true; }
|
||||
case (ast.expr_unary(_,_,_)) { ret true; }
|
||||
case (ast.expr_lit(_,_)) { ret true; }
|
||||
|
@ -160,8 +160,9 @@ tag token {
|
||||
FN;
|
||||
ITER;
|
||||
|
||||
/* Object type */
|
||||
/* Object type and related keywords */
|
||||
OBJ;
|
||||
SELF;
|
||||
|
||||
/* Comm and task types */
|
||||
CHAN;
|
||||
|
@ -757,6 +757,7 @@ fn expr_ty(@ast.expr expr) -> @t {
|
||||
case (ast.expr_rec(_, _, ?ann)) { ret ann_to_type(ann); }
|
||||
case (ast.expr_bind(_, _, ?ann)) { ret ann_to_type(ann); }
|
||||
case (ast.expr_call(_, _, ?ann)) { ret ann_to_type(ann); }
|
||||
case (ast.expr_call_self(_, _, ?ann)) { ret ann_to_type(ann); }
|
||||
case (ast.expr_spawn(_, _, _, _, ?ann))
|
||||
{ ret ann_to_type(ann); }
|
||||
case (ast.expr_binary(_, _, _, ?ann)) { ret ann_to_type(ann); }
|
||||
|
@ -1312,6 +1312,13 @@ fn demand_expr_full(&@fn_ctxt fcx, @ty.t expected, @ast.expr e,
|
||||
ann_to_type(ann), adk);
|
||||
e_1 = ast.expr_call(sube, es, ast.ann_type(t, none[vec[@ty.t]]));
|
||||
}
|
||||
case (ast.expr_call_self(?sube, ?es, ?ann)) {
|
||||
auto t = demand_full(fcx, e.span, expected,
|
||||
ann_to_type(ann), adk);
|
||||
e_1 = ast.expr_call_self(sube,
|
||||
es,
|
||||
ast.ann_type(t, none[vec[@ty.t]]));
|
||||
}
|
||||
case (ast.expr_binary(?bop, ?lhs, ?rhs, ?ann)) {
|
||||
auto t = demand(fcx, e.span, expected, ann_to_type(ann));
|
||||
e_1 = ast.expr_binary(bop, lhs, rhs,
|
||||
|
13
src/test/compile-fail/self-missing-method.rs
Normal file
13
src/test/compile-fail/self-missing-method.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// xfail-boot
|
||||
// error-pattern:expecting ., found (
|
||||
fn main() {
|
||||
|
||||
obj foo() {
|
||||
fn m() {
|
||||
self();
|
||||
}
|
||||
}
|
||||
|
||||
auto a = foo;
|
||||
a.m();
|
||||
}
|
16
src/test/run-pass/obj-self.rs
Normal file
16
src/test/run-pass/obj-self.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// xfail-boot
|
||||
fn main() {
|
||||
|
||||
obj foo() {
|
||||
fn m1() {
|
||||
log "hi!";
|
||||
}
|
||||
fn m2() {
|
||||
self.m1();
|
||||
}
|
||||
}
|
||||
|
||||
auto a = foo();
|
||||
a.m1();
|
||||
a.m2();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user