From 5679f5c55e15e4a42542c36b1abc86b469903d19 Mon Sep 17 00:00:00 2001 From: Lindsey Kuper Date: Fri, 13 May 2011 17:26:14 -0700 Subject: 'with' no longer a token; whitespace police. Plus renaming the anonymous objects test to a more descriptive name, and XFAILing it because it doesn't work yet. --- src/comp/front/parser.rs | 14 +++++--------- src/comp/middle/typeck.rs | 18 +++++++++--------- src/test/run-pass/anon-objs.rs | 33 +++++++++++++++++++++++++++++++++ src/test/run-pass/method-overriding.rs | 32 -------------------------------- 4 files changed, 47 insertions(+), 50 deletions(-) create mode 100644 src/test/run-pass/anon-objs.rs delete mode 100644 src/test/run-pass/method-overriding.rs (limited to 'src') diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 8eb6c398..767e7e93 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -801,15 +801,11 @@ fn parse_bottom_expr(parser p) -> @ast::expr { expect(p, token::LBRACE); while (p.peek() != token::RBRACE) { - alt (p.peek()) { - case (token::WITH) { - p.bump(); - with_obj = some[ast::ident](parse_ident(p)); - } - case (_) { - _vec::push[@ast::method](meths, - parse_method(p)); - } + if (eat_word(p, "with")) { + with_obj = some[ast::ident](parse_ident(p)); + } else { + _vec::push[@ast::method](meths, + parse_method(p)); } } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 99b2111e..3a620fa7 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -762,7 +762,7 @@ mod Collect { } } } - + // Anonymous objects are expressions, not items, but they're enough like // items that we're going to include them in this fold. fn fold_expr_anon_obj(&@env e, &span sp, @@ -1544,8 +1544,8 @@ mod Pushdown { write_type_only(fcx.ccx.node_types, ast::ann_tag(ann), t); } /* FIXME: should this check the type annotations? */ - case (ast::expr_fail(_)) { e_1 = e.node; } - case (ast::expr_log(_,_,_)) { e_1 = e.node; } + case (ast::expr_fail(_)) { e_1 = e.node; } + case (ast::expr_log(_,_,_)) { e_1 = e.node; } case (ast::expr_break(_)) { e_1 = e.node; } case (ast::expr_cont(_)) { e_1 = e.node; } case (ast::expr_ret(_,_)) { e_1 = e.node; } @@ -2262,7 +2262,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) -> @ast::expr { + "slot variables or literals"); } } - + require_pure_function(fcx.ccx, d_id, expr.span); ret @fold::respan[ast::expr_] @@ -2574,7 +2574,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) -> @ast::expr { case (ast::expr_call(?f, ?args, ?a)) { /* here we're kind of hosed, as f can be any expr need to restrict it to being an explicit expr_path if we're - inside a pure function, and need an environment mapping from + inside a pure function, and need an environment mapping from function name onto purity-designation */ require_pure_call(fcx.ccx, fcx.purity, f, expr.span); @@ -2613,10 +2613,10 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) -> @ast::expr { } // Otherwise, we should be able to look up the object we're // "with". - case (_) { + case (_) { // TODO. - - fail; + + fail; } } @@ -2886,7 +2886,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) -> @ast::expr { expr_ty(fcx.ccx.tcx, fcx.ccx.node_types, base_1)); auto idx_1 = check_expr(fcx, idx); - auto idx_t = expr_ty(fcx.ccx.tcx, fcx.ccx.node_types, idx_1); + auto idx_t = expr_ty(fcx.ccx.tcx, fcx.ccx.node_types, idx_1); alt (struct(fcx.ccx.tcx, base_t)) { case (ty::ty_vec(?mt)) { if (! type_is_integral(fcx.ccx.tcx, idx_t)) { diff --git a/src/test/run-pass/anon-objs.rs b/src/test/run-pass/anon-objs.rs new file mode 100644 index 00000000..14279db2 --- /dev/null +++ b/src/test/run-pass/anon-objs.rs @@ -0,0 +1,33 @@ +// xfail-boot +// xfail-stage0 +// xfail-stage1 +use std; + +fn main() { + + obj a() { + fn foo() -> int { + ret 2; + } + fn bar() -> int { + ret self.foo(); + } + } + + auto my_a = a(); + + // Extending an object with a new method + auto my_b = obj { + fn baz() -> int { + ret self.foo(); + } + with my_a + }; + + // Extending an object with a new field + auto my_c = obj(int quux) { with my_a } ; + + // Should this be legal? + auto my_d = obj() { with my_a } ; + +} diff --git a/src/test/run-pass/method-overriding.rs b/src/test/run-pass/method-overriding.rs deleted file mode 100644 index c76123fe..00000000 --- a/src/test/run-pass/method-overriding.rs +++ /dev/null @@ -1,32 +0,0 @@ -// xfail-boot -// xfail-stage0 -use std; - -fn main() { - - obj a() { - fn foo() -> int { - ret 2; - } - fn bar() -> int { - ret self.foo(); - } - } - - auto my_a = a(); - - // Extending an object with a new method - auto my_b = obj { - fn baz() -> int { - ret self.foo(); - } - with my_a - }; - - // Extending an object with a new field - auto my_c = obj(int quux) { with my_a } ; - - // Should this be legal? - auto my_d = obj() { with my_a } ; - -} -- cgit v1.2.3