@@ -25,7 +25,7 @@ public abstract class ComprehensionIterator : Node {
2525 }
2626
2727 public abstract class Comprehension : Expression {
28- public abstract IList < ComprehensionIterator > Iterators { get ; }
28+ public abstract IReadOnlyList < ComprehensionIterator > Iterators { get ; }
2929 public abstract override string NodeName { get ; }
3030
3131 protected abstract MSAst . ParameterExpression MakeParameter ( ) ;
@@ -85,7 +85,7 @@ public ListComprehension(Expression item, ComprehensionIterator[] iterators) {
8585
8686 public Expression Item { get ; }
8787
88- public override IList < ComprehensionIterator > Iterators => _iterators ;
88+ public override IReadOnlyList < ComprehensionIterator > Iterators => _iterators ;
8989
9090 protected override MSAst . ParameterExpression MakeParameter ( )
9191 => Ast . Parameter ( typeof ( PythonList ) , "list_comprehension_list" ) ;
@@ -134,7 +134,7 @@ public SetComprehension(Expression item, ComprehensionIterator[] iterators) {
134134
135135 public Expression Item { get ; }
136136
137- public override IList < ComprehensionIterator > Iterators => _iterators ;
137+ public override IReadOnlyList < ComprehensionIterator > Iterators => _iterators ;
138138
139139 protected override MSAst . ParameterExpression MakeParameter ( )
140140 => Ast . Parameter ( typeof ( SetCollection ) , "set_comprehension_set" ) ;
@@ -186,7 +186,7 @@ public DictionaryComprehension(Expression key, Expression value, ComprehensionIt
186186
187187 public Expression Value { get ; }
188188
189- public override IList < ComprehensionIterator > Iterators => _iterators ;
189+ public override IReadOnlyList < ComprehensionIterator > Iterators => _iterators ;
190190
191191 protected override MSAst . ParameterExpression MakeParameter ( )
192192 => Ast . Parameter ( typeof ( PythonDictionary ) , "dict_comprehension_dict" ) ;
@@ -280,6 +280,7 @@ internal override bool TryBindOuter(ScopeStatement from, PythonReference referen
280280 }
281281
282282 internal override PythonVariable BindReference ( PythonNameBinder binder , PythonReference reference ) {
283+ // First try variables local to this scope
283284 if ( TryGetVariable ( reference . Name , out PythonVariable variable ) ) {
284285 if ( variable . Kind == VariableKind . Global ) {
285286 AddReferencedGlobal ( reference . Name ) ;
@@ -288,8 +289,14 @@ internal override PythonVariable BindReference(PythonNameBinder binder, PythonRe
288289 return variable ;
289290 }
290291
291- // then bind in our parent scope
292- return Parent . BindReference ( binder , reference ) ;
292+ // then try to bind in outer scopes
293+ for ( ScopeStatement parent = Parent ; parent != null ; parent = parent . Parent ) {
294+ if ( parent . TryBindOuter ( this , reference , out variable ) ) {
295+ return variable ;
296+ }
297+ }
298+
299+ return null ;
293300 }
294301
295302 internal override Ast GetVariableExpression ( PythonVariable variable ) {
0 commit comments