Commit 6fecfd16 authored by Travis Hance's avatar Travis Hance

address kmod's comments on static closures

parent 5082369a
...@@ -98,8 +98,8 @@ public: ...@@ -98,8 +98,8 @@ public:
virtual DerefInfo getDerefInfo(InternedString name) = 0; virtual DerefInfo getDerefInfo(InternedString name) = 0;
// Gets the DerefInfo for each DEREF variable accessible in the scope. // Gets the DerefInfo for each DEREF variable accessible in the scope.
// The returned vector is in SORTED ORDER by the `num_parents_from_passed_closure` field. // The returned vector is in SORTED ORDER by the `num_parents_from_passed_closure` field
// This allows the caller to iterate through the vector while also walking up // (ascending). This allows the caller to iterate through the vector while also walking up
// the closure chain to collect all the DEREF variable values. This is useful, for example, // the closure chain to collect all the DEREF variable values. This is useful, for example,
// in the implementation of locals(). // in the implementation of locals().
// //
......
...@@ -1277,7 +1277,6 @@ Box* getattrInternalGeneric(Box* obj, const std::string& attr, GetattrRewriteArg ...@@ -1277,7 +1277,6 @@ Box* getattrInternalGeneric(Box* obj, const std::string& attr, GetattrRewriteArg
*bind_obj_out = NULL; *bind_obj_out = NULL;
} }
// TODO this should be a custom getattr
assert(obj->cls != closure_cls); assert(obj->cls != closure_cls);
// Handle descriptor logic here. // Handle descriptor logic here.
......
# should_error
# The use of c makes sure a closure gets passed through all 4 functions. # The use of c makes sure a closure gets passed through all 4 functions.
# The use of a in g makes sure that a is in f's closure. # The use of a in g makes sure that a is in f's closure.
# The a in j should refer to the a in h, thus throwing an exception since # The a in j should refer to the a in h, thus throwing an exception since
# it is undefined (that is, it should *not* access the a from f even # it is undefined (that is, it should *not* access the a from f even
# though it access via the closure). # though it access via the closure).
def f(): try:
c = 0 def f():
a = 0 c = 0
def g(): a = 0
print c def g():
print a
def h():
print c print c
def j(): print a
def h():
print c print c
print a def j():
print c
print a
j() j()
a = 1 a = 1
h() h()
g() g()
f() f()
except NameError as ne:
print ne.message
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment