mirror of
https://github.com/github/codeql.git
synced 2026-05-03 04:39:29 +02:00
Extract no-when-branch-found calls
These are extracted as "throw new kotlin.NoWhenBranchFoundException();", which is the Java lowering of the intrinsic. In the process, amend the control-flow graph to let when branches propagate `throw`s outwards, and similarly statement expressions.
This commit is contained in:
committed by
Ian Lynagh
parent
d09dff482c
commit
5fe65ed983
@@ -914,7 +914,7 @@ private module ControlFlowGraphImpl {
|
||||
last(n.(ExprStmt).getExpr(), last, completion) and completion = NormalCompletion()
|
||||
or
|
||||
// the last node in a `StmtExpr` is the last node in the statement
|
||||
last(n.(StmtExpr).getStmt(), last, completion) and completion = NormalCompletion()
|
||||
last(n.(StmtExpr).getStmt(), last, completion)
|
||||
or
|
||||
// the last statement of a labeled statement is the last statement of its body...
|
||||
exists(LabeledStmt lbl, Completion bodyCompletion |
|
||||
@@ -950,7 +950,7 @@ private module ControlFlowGraphImpl {
|
||||
not exists(whenexpr.getBranch(i + 1))
|
||||
)
|
||||
or
|
||||
// Any branch getting an abnormal completion is propogated
|
||||
// Any branch getting an abnormal completion is propagated
|
||||
last(whenexpr.getBranch(_), last, completion) and
|
||||
not completion instanceof YieldCompletion and
|
||||
not completion instanceof NormalOrBooleanCompletion
|
||||
@@ -969,6 +969,11 @@ private module ControlFlowGraphImpl {
|
||||
not completion = BooleanCompletion(true, _) and
|
||||
not completion = NormalCompletion()
|
||||
or
|
||||
// Similarly any non-normal completion of the RHS
|
||||
// should propagate outwards:
|
||||
last(whenbranch.getRhs(), last, completion) and
|
||||
not completion instanceof NormalOrBooleanCompletion
|
||||
or
|
||||
// Otherwise we wrap the completion up in a YieldCompletion
|
||||
// so that the `when` expression can tell that we have finished,
|
||||
// and it shouldn't go on to the next branch.
|
||||
|
||||
Reference in New Issue
Block a user