diff options
author | da-woods <dw-git@d-woods.co.uk> | 2022-07-16 09:49:13 +0100 |
---|---|---|
committer | da-woods <dw-git@d-woods.co.uk> | 2022-07-16 09:49:13 +0100 |
commit | bf4858d6de33609738a7334dd58546c9ab137248 (patch) | |
tree | 748156077ca9de485adb2067e300ccf167bf6556 | |
parent | fc76d4ab03399e6cd0393e562124328f61cbc1c6 (diff) | |
parent | 585f0ede1a5d065b169a0d02a6e245d9b79d9856 (diff) | |
download | cython-bf4858d6de33609738a7334dd58546c9ab137248.tar.gz |
Merge branch 'match-targets' into match-sequence
-rw-r--r-- | Cython/Compiler/FlowControl.py | 21 | ||||
-rw-r--r-- | Cython/Compiler/MatchCaseNodes.py | 7 |
2 files changed, 21 insertions, 7 deletions
diff --git a/Cython/Compiler/FlowControl.py b/Cython/Compiler/FlowControl.py index b00997375..a046981a9 100644 --- a/Cython/Compiler/FlowControl.py +++ b/Cython/Compiler/FlowControl.py @@ -954,29 +954,38 @@ class ControlFlowAnalysis(CythonTransform): self._visit(node.subject) next_block = self.flow.newblock() - parent = self.flow.block + orig_parent = self.flow.block + guard_block = None for case in node.cases: if isinstance(case, MatchCaseNode): - self.flow.nextblock(parent) + case_block = self.flow.nextblock(orig_parent) + if guard_block: + guard_block.add_child(case_block) self._visit(case.pattern) self.flow.nextblock() if case.target_assignments: self._visit(case.target_assignments) if case.guard: - parent = self.flow.nextblock() + guard_block = self.flow.nextblock() self._visit(case.guard) + else: + guard_block = None self.flow.nextblock() self._visit(case.body) if self.flow.block: self.flow.block.add_child(next_block) elif isinstance(case, SubstitutedMatchCaseNode): + self.flow.nextblock() + if guard_block: + guard_block.add_child(self.flow.block) + guard_block = None self._visit(case.body) - parent = self.flow.block + orig_parent = self.flow.block else: assert False, case - if parent is not None: - parent.add_child(next_block) + if orig_parent is not None: + orig_parent.add_child(next_block) if next_block.parents: self.flow.block = next_block else: diff --git a/Cython/Compiler/MatchCaseNodes.py b/Cython/Compiler/MatchCaseNodes.py index 0ba4453c2..10895d51d 100644 --- a/Cython/Compiler/MatchCaseNodes.py +++ b/Cython/Compiler/MatchCaseNodes.py @@ -537,7 +537,12 @@ class OrPatternNode(PatternNode): a.validate_irrefutable() def is_simple_value_comparison(self): - return all(a.is_simple_value_comparison() for a in self.alternatives) + return all( + # it turns out to be hard to generate correct assignment code + # for or patterns with targets + a.is_simple_value_comparison() and not a.get_targets() + for a in self.alternatives + ) def get_simple_comparison_node(self, subject_node): assert self.is_simple_value_comparison() |