mirror of
https://github.com/github/codeql.git
synced 2026-05-27 09:31:30 +02:00
Adds concrete `Pattern` subclasses in `AstNodeImpl.qll` for every
`MatchPattern` AST kind, with `getChild` overrides that expose
sub-patterns and bound Names. Specifically:
- MatchCapturePattern (`case x:`) -> getVariable()
- MatchAsPattern (`case … as v:`) -> getPattern(), getAlias()
- MatchStarPattern (`case [*rest]:`) -> getTarget()
- MatchSequencePattern (`case [a, b]:`) -> getPattern(i)
- MatchClassPattern (`case Cls(p, q, k=v)`) -> getClass(), positional, keyword
- MatchMappingPattern (`case {k: v}:`) -> getMapping(i)
- MatchKeyValuePattern, MatchKeywordPattern, MatchDoubleStarPattern
- MatchOrPattern, MatchLiteralPattern, MatchValuePattern
Without these, every Name bound by a match pattern lacked a CFG node.
Removes the corresponding MISSING: annotations from match_pattern.py
(all 11 cases).
Verified: all 24 ControlFlow/evaluation-order tests still pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
25 lines
671 B
Python
25 lines
671 B
Python
# Match-statement pattern bindings — wired in the new CFG.
|
|
|
|
def f(subject): # $ cfgdefines=f cfgdefines=subject
|
|
match subject:
|
|
case x: # $ cfgdefines=x
|
|
pass
|
|
case [a, b]: # $ cfgdefines=a cfgdefines=b
|
|
pass
|
|
case {"k": v}: # $ cfgdefines=v
|
|
pass
|
|
case Point(p, q): # $ cfgdefines=p cfgdefines=q
|
|
pass
|
|
case [_, *rest]: # $ cfgdefines=rest
|
|
pass
|
|
case (1 | 2) as n: # $ cfgdefines=n
|
|
pass
|
|
|
|
|
|
class Point: # $ cfgdefines=Point
|
|
__match_args__ = ("x", "y") # $ cfgdefines=__match_args__
|
|
x: int # $ cfgdefines=x
|
|
y: int # $ cfgdefines=y
|
|
|
|
|