mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Python: Fix ExceptStmt::getType
We were not supporting `except` statements handling multiple exception types (specified as a tuple) correctly, instead just returning the tuple itself as the "type" (which makes little sense). To fix this, we explicitly extract the elements of this node, in the case where it _is_ a tuple. This is a change that can potentially affect many queries (as `getType` is used in quite a few places), so some care should be taken to ensure that this does not adversely affect performance.
This commit is contained in:
@@ -153,6 +153,12 @@ class ExceptStmt extends ExceptStmt_ {
|
||||
override Stmt getASubStatement() { result = this.getAStmt() }
|
||||
|
||||
override Stmt getLastStatement() { result = this.getBody().getLastItem().getLastStatement() }
|
||||
|
||||
override Expr getType() {
|
||||
result = super.getType() and not result instanceof Tuple
|
||||
or
|
||||
result = super.getType().(Tuple).getAnElt()
|
||||
}
|
||||
}
|
||||
|
||||
/** An assert statement, such as `assert a == b, "A is not equal to b"` */
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
| test.py:5:15:5:22 | ControlFlowNode for next() | Call to next() in a generator |
|
||||
| test.py:10:20:10:27 | ControlFlowNode for next() | Call to next() in a generator |
|
||||
| test.py:62:19:62:28 | ControlFlowNode for next() | Call to next() in a generator |
|
||||
|
||||
Reference in New Issue
Block a user