@@ -317,8 +317,8 @@ fn resolve_import(&env e, &@ast::view_item it, &list[scope] sc) {
317
317
318
318
if ( n_idents == 1 u) {
319
319
register ( e, defid, it. span , end_id,
320
- lookup_in_scope ( e, sc, end_id, ns_value) ,
321
- lookup_in_scope ( e, sc, end_id, ns_type) ) ;
320
+ lookup_in_scope ( e, sc, it . span , end_id, ns_value) ,
321
+ lookup_in_scope ( e, sc, it . span , end_id, ns_type) ) ;
322
322
} else {
323
323
auto dcur = lookup_in_scope_strict ( e, sc, it. span , ids. ( 0 ) , ns_value) ;
324
324
auto i = 1 u;
@@ -394,7 +394,7 @@ fn lookup_path_strict(&env e, &list[scope] sc, &span sp, vec[ident] idents,
394
394
395
395
fn lookup_in_scope_strict ( & env e, list[ scope] sc , & span sp, ident id,
396
396
namespace ns) -> def {
397
- alt ( lookup_in_scope ( e, sc, id, ns) ) {
397
+ alt ( lookup_in_scope ( e, sc, sp , id, ns) ) {
398
398
case ( none[ def] ) {
399
399
unresolved ( e, sp, id, ns_name ( ns) ) ;
400
400
fail;
@@ -405,7 +405,35 @@ fn lookup_in_scope_strict(&env e, list[scope] sc, &span sp, ident id,
405
405
}
406
406
}
407
407
408
- fn lookup_in_scope ( & env e, list[ scope] sc , ident id, namespace ns)
408
+ fn scope_is_fn ( & scope sc) -> bool {
409
+ ret alt ( sc) {
410
+ case ( scope_item ( ?it) ) {
411
+ alt ( it. node ) {
412
+ case ( ast:: item_fn ( _, _, _, _, _) ) { true }
413
+ case ( _) { false }
414
+ }
415
+ }
416
+ case ( scope_native_item ( _) ) { true }
417
+ case ( _) { false }
418
+ } ;
419
+ }
420
+
421
+ fn def_is_local ( & def d) -> bool {
422
+ ret alt ( d) {
423
+ case ( ast:: def_arg ( _) ) { true }
424
+ case ( ast:: def_local ( _) ) { true }
425
+ case ( ast:: def_binding ( _) ) { true }
426
+ case ( _) { false }
427
+ } ;
428
+ }
429
+ fn def_is_obj_field ( & def d) -> bool {
430
+ ret alt ( d) {
431
+ case ( ast:: def_obj_field ( _) ) { true }
432
+ case ( _) { false }
433
+ } ;
434
+ }
435
+
436
+ fn lookup_in_scope ( & env e, list[ scope] sc , & span sp, ident id, namespace ns)
409
437
-> option:: t [ def ] {
410
438
fn in_scope ( & env e, ident id, & scope s, namespace ns)
411
439
-> option:: t [ def ] {
@@ -441,15 +469,13 @@ fn lookup_in_scope(&env e, list[scope] sc, ident id, namespace ns)
441
469
case ( _) { }
442
470
}
443
471
}
444
-
445
472
case ( scope_native_item ( ?it) ) {
446
473
alt ( it. node ) {
447
474
case ( ast:: native_item_fn ( _, _, ?decl, ?ty_params, _, _) ) {
448
475
ret lookup_in_fn ( id, decl, ty_params, ns) ;
449
476
}
450
477
}
451
478
}
452
-
453
479
case ( scope_loop ( ?d) ) {
454
480
if ( ns == ns_value) {
455
481
alt ( d. node ) {
@@ -461,11 +487,9 @@ fn lookup_in_scope(&env e, list[scope] sc, ident id, namespace ns)
461
487
}
462
488
}
463
489
}
464
-
465
490
case ( scope_block ( ?b) ) {
466
491
ret lookup_in_block ( id, b. node , ns) ;
467
492
}
468
-
469
493
case ( scope_arm ( ?a) ) {
470
494
if ( ns == ns_value) {
471
495
ret lookup_in_pat ( id, * a. pat ) ;
@@ -475,16 +499,30 @@ fn lookup_in_scope(&env e, list[scope] sc, ident id, namespace ns)
475
499
ret none[ def] ;
476
500
}
477
501
502
+ auto left_fn = false ;
503
+ // Used to determine whether obj fields are in scope
504
+ auto left_fn_level2 = false ;
478
505
while ( true ) {
479
506
alt ( sc) {
480
507
case ( nil[ scope] ) {
481
508
ret none[ def] ;
482
509
}
483
510
case ( cons[ scope] ( ?hd, ?tl) ) {
484
- alt ( in_scope ( e, id, hd, ns) ) {
485
- case ( some[ def] ( ?x) ) { ret some ( x) ; }
486
- case ( _) { sc = * tl; }
511
+ auto fnd = in_scope ( e, id, hd, ns) ;
512
+ if ( fnd != none[ def] ) {
513
+ auto df = option:: get ( fnd) ;
514
+ if ( ( left_fn && def_is_local ( df) ) ||
515
+ ( left_fn_level2 && def_is_obj_field ( df) ) ) {
516
+ e. sess . span_err ( sp, "attempted dynamic " +
517
+ "environment-capture" ) ;
518
+ }
519
+ ret fnd;
520
+ }
521
+ if ( left_fn) { left_fn_level2 = true ; }
522
+ if ( ns == ns_value && !left_fn) {
523
+ left_fn = scope_is_fn ( hd) ;
487
524
}
525
+ sc = * tl;
488
526
}
489
527
}
490
528
}
@@ -841,7 +879,6 @@ fn check_def_by_ns(def d, namespace ns) -> bool {
841
879
case ( ast:: def_const ( ?id) ) { ns == ns_value }
842
880
case ( ast:: def_arg ( ?id) ) { ns == ns_value }
843
881
case ( ast:: def_local ( ?id) ) { ns == ns_value }
844
- case ( ast:: def_upvar ( ?id) ) { ns == ns_value }
845
882
case ( ast:: def_variant ( _, ?id) ) { ns == ns_value }
846
883
case ( ast:: def_ty ( ?id) ) { ns == ns_type }
847
884
case ( ast:: def_binding ( ?id) ) { ns == ns_type }
0 commit comments