@@ -658,9 +658,9 @@ fn expand_non_macro_stmt(s: &Stmt, fld: &mut MacroExpander)
658
658
}
659
659
}
660
660
661
- // a visitor that extracts the pat_ident paths
661
+ // a visitor that extracts the pat_ident (binding) paths
662
662
// from a given thingy and puts them in a mutable
663
- // array (passed in to the traversal)
663
+ // array (passed in to the traversal).
664
664
#[ deriving( Clone ) ]
665
665
pub struct NewNameFinderContext {
666
666
ident_accumulator : Vec < ast:: Ident > ,
@@ -1026,7 +1026,7 @@ mod test {
1026
1026
use parse;
1027
1027
use parse:: token;
1028
1028
use util:: parser_testing:: { string_to_parser} ;
1029
- use util:: parser_testing:: { string_to_pat, strs_to_idents} ;
1029
+ use util:: parser_testing:: { string_to_pat, string_to_crate , strs_to_idents} ;
1030
1030
use visit;
1031
1031
use visit:: Visitor ;
1032
1032
@@ -1059,7 +1059,7 @@ mod test {
1059
1059
}
1060
1060
1061
1061
// return a visitor that extracts the paths
1062
- // from a given pattern and puts them in a mutable
1062
+ // from a given thingy and puts them in a mutable
1063
1063
// array (passed in to the traversal)
1064
1064
pub fn new_path_finder ( paths : Vec < ast:: Path > ) -> NewPathExprFinderContext {
1065
1065
NewPathExprFinderContext {
@@ -1188,7 +1188,7 @@ mod test {
1188
1188
// The comparisons are done post-mtwt-resolve, so we're comparing renamed
1189
1189
// names; differences in marks don't matter any more.
1190
1190
//
1191
- // oog... I also want tests that check "binding -identifier-=?". That is,
1191
+ // oog... I also want tests that check "bound -identifier-=?". That is,
1192
1192
// not just "do these have the same name", but "do they have the same
1193
1193
// name *and* the same marks"? Understanding this is really pretty painful.
1194
1194
// in principle, you might want to control this boolean on a per-varref basis,
@@ -1217,12 +1217,55 @@ mod test {
1217
1217
( "macro_rules! letty(($x:ident) => (let $x = 15;))
1218
1218
macro_rules! user(($x:ident) => ({letty!($x); $x}))
1219
1219
fn main() -> int {user!(z)}" ,
1220
- vec!( vec!( 0 ) ) , false ) ) ;
1220
+ vec!( vec!( 0 ) ) , false )
1221
+ ) ;
1221
1222
for ( idx, s) in tests. iter ( ) . enumerate ( ) {
1222
1223
run_renaming_test ( s, idx) ;
1223
1224
}
1224
1225
}
1225
1226
1227
+ // no longer a fixme #8062: this test exposes a *potential* bug; our system does
1228
+ // not behave exactly like MTWT, but a conversation with Matthew Flatt
1229
+ // suggests that this can only occur in the presence of local-expand, which
1230
+ // we have no plans to support. ... unless it's needed for item hygiene....
1231
+ #[ ignore]
1232
+ #[ test] fn issue_8062 ( ) {
1233
+ run_renaming_test (
1234
+ & ( "fn main() {let hrcoo = 19; macro_rules! getx(()=>(hrcoo)); getx!();}" ,
1235
+ vec ! ( vec!( 0 ) ) , true ) , 0 )
1236
+ }
1237
+
1238
+ // FIXME #6994:
1239
+ // the z flows into and out of two macros (g & f) along one path, and one
1240
+ // (just g) along the other, so the result of the whole thing should
1241
+ // be "let z_123 = 3; z_123"
1242
+ #[ ignore]
1243
+ #[ test] fn issue_6994 ( ) {
1244
+ run_renaming_test (
1245
+ & ( "macro_rules! g (($x:ident) =>
1246
+ ({macro_rules! f(($y:ident)=>({let $y=3;$x}));f!($x)}))
1247
+ fn a(){g!(z)}" ,
1248
+ vec ! ( vec!( 0 ) ) , false ) ,
1249
+ 0 )
1250
+ }
1251
+
1252
+ // create a really evil test case where a $x appears inside a binding of $x
1253
+ // but *shouldnt* bind because it was inserted by a different macro....
1254
+ // can't write this test case until we have macro-generating macros.
1255
+
1256
+ // FIXME #9383 : lambda var hygiene
1257
+ // interesting... can't even write this test, yet, because the name-finder
1258
+ // only finds pattern vars. Time to upgrade test framework.
1259
+ /*#[test]
1260
+ fn issue_9383(){
1261
+ run_renaming_test(
1262
+ &("macro_rules! bad_macro (($ex:expr) => ({(|_x| { $ex }) (9) }))
1263
+ fn takes_x(_x : int) { assert_eq!(bad_macro!(_x),8); }
1264
+ fn main() { takes_x(8); }",
1265
+ vec!(vec!()),false),
1266
+ 0)
1267
+ }*/
1268
+
1226
1269
// run one of the renaming tests
1227
1270
fn run_renaming_test ( t : & RenamingTest , test_idx : uint ) {
1228
1271
let invalid_name = token:: special_idents:: invalid. name ;
@@ -1358,4 +1401,13 @@ foo_module!()
1358
1401
strs_to_idents( vec!( "a" , "c" , "b" , "d" ) ) ) ;
1359
1402
}
1360
1403
1404
+ #[ test]
1405
+ fn pat_idents_2 ( ) {
1406
+ let the_crate = string_to_crate ( "fn main (a : int) -> int {|b| {a + b} }" . to_string ( ) ) ;
1407
+ let mut pat_idents = new_name_finder ( Vec :: new ( ) ) ;
1408
+ pat_idents. visit_mod ( & the_crate. module , the_crate. span , ast:: CRATE_NODE_ID , ( ) ) ;
1409
+ assert_eq ! ( pat_idents. ident_accumulator,
1410
+ strs_to_idents( vec!( "a" , "b" ) ) ) ;
1411
+ }
1412
+
1361
1413
}
0 commit comments