Skip to content

Commit 06df583

Browse files
authored
Fix the next_block attribute of the new block in ControlFlowGraph.split_block (#170)
* Fix the next_block of the new block in ControlFlowGraph.split_block * Improve the split_block tests to verify the next blocks
1 parent 12df292 commit 06df583

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/bytecode/cfg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ def split_block(self, block: BasicBlock, index: int) -> BasicBlock:
710710
del block[index:]
711711

712712
block2 = BasicBlock(instructions)
713+
block2.next_block = block.next_block
713714
block.next_block = block2
714715

715716
for block in self[block_index + 1 :]:

tests/test_cfg.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ def test_split_block(self):
534534

535535
label = code.split_block(code[0], 2)
536536
self.assertIs(label, code[1])
537+
self.assertIs(code[0].next_block, label)
538+
self.assertIs(label.next_block, None)
537539
self.assertBlocksEqual(
538540
code,
539541
[
@@ -546,6 +548,9 @@ def test_split_block(self):
546548

547549
label2 = code.split_block(code[0], 1)
548550
self.assertIs(label2, code[1])
551+
self.assertIs(code[0].next_block, label2)
552+
self.assertIs(label2.next_block, label)
553+
self.assertIs(label.next_block, None)
549554
self.assertBlocksEqual(
550555
code,
551556
[Instr("LOAD_SMALL_INT" if PY314 else "LOAD_CONST", 1, lineno=1)],
@@ -567,6 +572,8 @@ def test_split_block_end(self):
567572
# split at the end of the last block requires to add a new empty block
568573
label = code.split_block(code[0], 2)
569574
self.assertIs(label, code[1])
575+
self.assertIs(code[0].next_block, label)
576+
self.assertIs(label.next_block, None)
570577
self.assertBlocksEqual(
571578
code,
572579
[
@@ -581,6 +588,8 @@ def test_split_block_end(self):
581588
# add a new block
582589
label = code.split_block(code[0], 2)
583590
self.assertIs(label, code[1])
591+
self.assertIs(code[0].next_block, label)
592+
self.assertIs(label.next_block, None)
584593
self.assertBlocksEqual(
585594
code,
586595
[
@@ -596,6 +605,7 @@ def test_split_block_dont_split(self):
596605
# FIXME: is it really useful to support that?
597606
block = code.split_block(code[0], 0)
598607
self.assertIs(block, code[0])
608+
self.assertIs(code[0].next_block, None)
599609
self.assertBlocksEqual(
600610
code,
601611
[

0 commit comments

Comments
 (0)