@@ -25,7 +25,7 @@ public abstract class ComprehensionIterator : Node {
25
25
}
26
26
27
27
public abstract class Comprehension : Expression {
28
- public abstract IList < ComprehensionIterator > Iterators { get ; }
28
+ public abstract IReadOnlyList < ComprehensionIterator > Iterators { get ; }
29
29
public abstract override string NodeName { get ; }
30
30
31
31
protected abstract MSAst . ParameterExpression MakeParameter ( ) ;
@@ -85,7 +85,7 @@ public ListComprehension(Expression item, ComprehensionIterator[] iterators) {
85
85
86
86
public Expression Item { get ; }
87
87
88
- public override IList < ComprehensionIterator > Iterators => _iterators ;
88
+ public override IReadOnlyList < ComprehensionIterator > Iterators => _iterators ;
89
89
90
90
protected override MSAst . ParameterExpression MakeParameter ( )
91
91
=> Ast . Parameter ( typeof ( PythonList ) , "list_comprehension_list" ) ;
@@ -134,7 +134,7 @@ public SetComprehension(Expression item, ComprehensionIterator[] iterators) {
134
134
135
135
public Expression Item { get ; }
136
136
137
- public override IList < ComprehensionIterator > Iterators => _iterators ;
137
+ public override IReadOnlyList < ComprehensionIterator > Iterators => _iterators ;
138
138
139
139
protected override MSAst . ParameterExpression MakeParameter ( )
140
140
=> Ast . Parameter ( typeof ( SetCollection ) , "set_comprehension_set" ) ;
@@ -186,7 +186,7 @@ public DictionaryComprehension(Expression key, Expression value, ComprehensionIt
186
186
187
187
public Expression Value { get ; }
188
188
189
- public override IList < ComprehensionIterator > Iterators => _iterators ;
189
+ public override IReadOnlyList < ComprehensionIterator > Iterators => _iterators ;
190
190
191
191
protected override MSAst . ParameterExpression MakeParameter ( )
192
192
=> Ast . Parameter ( typeof ( PythonDictionary ) , "dict_comprehension_dict" ) ;
@@ -280,6 +280,7 @@ internal override bool TryBindOuter(ScopeStatement from, PythonReference referen
280
280
}
281
281
282
282
internal override PythonVariable BindReference ( PythonNameBinder binder , PythonReference reference ) {
283
+ // First try variables local to this scope
283
284
if ( TryGetVariable ( reference . Name , out PythonVariable variable ) ) {
284
285
if ( variable . Kind == VariableKind . Global ) {
285
286
AddReferencedGlobal ( reference . Name ) ;
@@ -288,8 +289,14 @@ internal override PythonVariable BindReference(PythonNameBinder binder, PythonRe
288
289
return variable ;
289
290
}
290
291
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 ;
293
300
}
294
301
295
302
internal override Ast GetVariableExpression ( PythonVariable variable ) {
0 commit comments