summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2022-11-19 17:35:24 +0000
committerda-woods <dw-git@d-woods.co.uk>2022-11-19 17:36:02 +0000
commit82f7e9bfca66144712e2b0f8f05c268737595385 (patch)
tree5e7d23c3e4fe2263196c29616f5c72a9d2fd9dcd
parent9299a3fefc6c93bdb11f7fc35025615f5c1c0d56 (diff)
downloadcython-82f7e9bfca66144712e2b0f8f05c268737595385.tar.gz
Avoid crashing due to ErrorNodes
-rw-r--r--Cython/Compiler/MatchCaseNodes.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Cython/Compiler/MatchCaseNodes.py b/Cython/Compiler/MatchCaseNodes.py
index dbd5b8770..96d297bc7 100644
--- a/Cython/Compiler/MatchCaseNodes.py
+++ b/Cython/Compiler/MatchCaseNodes.py
@@ -2,7 +2,7 @@
#
# In a separate file because they're unlikely to be useful for much else.
-from .Nodes import Node, StatNode
+from .Nodes import Node, StatNode, ErrorNode
from .Errors import error
@@ -17,6 +17,10 @@ class MatchNode(StatNode):
def validate_irrefutable(self):
found_irrefutable_case = None
for case in self.cases:
+ if isinstance(case, ErrorNode):
+ # This validation happens before error nodes have been
+ # transformed into actual errors, so we need to ignore them
+ continue
if found_irrefutable_case:
error(
found_irrefutable_case.pos,
@@ -45,12 +49,18 @@ class MatchCaseNode(Node):
child_attrs = ["pattern", "body", "guard"]
def is_irrefutable(self):
+ if isinstance(self.pattern, ErrorNode):
+ return True # value doesn't really matter
return self.pattern.is_irrefutable() and not self.guard
def validate_targets(self):
+ if isinstance(self.pattern, ErrorNode):
+ return
self.pattern.get_targets()
def validate_irrefutable(self):
+ if isinstance(self.pattern, ErrorNode):
+ return
self.pattern.validate_irrefutable()