1.1 --- a/internal_tests/branches.py Mon May 27 11:54:56 2019 +0200
1.2 +++ b/internal_tests/branches.py Sun Jun 02 23:10:26 2019 +0200
1.3 @@ -687,4 +687,77 @@
1.4 bt.get_assignment_positions_for_branches("a", ar)
1.5 names.append(bt.assignments["a"])
1.6
1.7 +# This demonstrates why the assignment in a "for" loop construct must appear
1.8 +# outside the inner "try" body: null usage escapes the loop via the exception
1.9 +# handler and the raise statement, even though the assignment would only be
1.10 +# valid otherwise.
1.11 +
1.12 +# Equivalent to...
1.13 +#
1.14 +# try:
1.15 +# while ...:
1.16 +# try:
1.17 +# a = ...
1.18 +# except:
1.19 +# raise ...
1.20 +# a.p
1.21 +# except:
1.22 +# pass
1.23 +
1.24 +bt = branching.BranchTracker()
1.25 +bt.new_branchpoint() # begin (try)
1.26 +bt.new_branchpoint(True) # begin (while)
1.27 +bt.new_branch(True) # while ...
1.28 +bt.new_branchpoint() # begin (try)
1.29 +a = bt.assign_names(["a"])
1.30 +bt.resume_abandoned_branches() # except
1.31 +bt.abandon_branch() # raise
1.32 +bt.shelve_branch()
1.33 +bt.new_branch() # (null)
1.34 +bt.shelve_branch()
1.35 +bt.merge_branches() # end (try)
1.36 +ap = bt.use_attribute("a", "p")
1.37 +bt.resume_continuing_branches()
1.38 +bt.shelve_branch(True)
1.39 +bt.new_branch() # (null)
1.40 +bt.shelve_branch()
1.41 +bt.merge_branches() # end (while)
1.42 +bt.resume_broken_branches()
1.43 +bt.resume_abandoned_branches() # except
1.44 +bt.shelve_branch()
1.45 +bt.new_branch() # (null)
1.46 +bt.shelve_branch()
1.47 +bt.merge_branches() # end (try)
1.48 +
1.49 +print simple_usage(a) == \
1.50 + {'a' : set([('p',), ()])}, simple_usage(a)
1.51 +print bt.get_assignment_positions_for_branches("a", ap) == [0], \
1.52 + bt.get_assignment_positions_for_branches("a", ap)
1.53 +names.append(bt.assignments["a"])
1.54 +
1.55 +# Equivalent to...
1.56 +#
1.57 +# b = ...
1.58 +# while ...:
1.59 +# a = ...
1.60 +# a.p
1.61 +
1.62 +bt = branching.BranchTracker()
1.63 +bt.new_branchpoint(True) # begin
1.64 +b = bt.assign_names(["b"])
1.65 +bt.new_branch(True) # while ...
1.66 +a = bt.assign_names(["a"])
1.67 +ap = bt.use_attribute("a", "p")
1.68 +bt.resume_continuing_branches()
1.69 +bt.shelve_branch(True)
1.70 +bt.new_branch() # (null)
1.71 +bt.shelve_branch()
1.72 +bt.merge_branches() # end
1.73 +
1.74 +print simple_usage(a) == \
1.75 + {'a' : set([('p',)])}, simple_usage(a)
1.76 +print bt.get_assignment_positions_for_branches("a", ap) == [0], \
1.77 + bt.get_assignment_positions_for_branches("a", ap)
1.78 +names.append(bt.assignments["a"])
1.79 +
1.80 # vim: tabstop=4 expandtab shiftwidth=4