Ruby: Fix CFG for nodes that may raise

This commit is contained in:
Tom Hvitved
2024-04-04 13:03:08 +02:00
parent 6d2d9654b5
commit ce3b359813
3 changed files with 9 additions and 11 deletions

View File

@@ -90,9 +90,7 @@ private predicate mayRaise(Call c) { c = getARescuableBodyChild() }
/** A completion of a statement or an expression. */
abstract class Completion extends TCompletion {
private predicate isValidForSpecific(AstNode n) {
exists(AstNode other | n = other.getDesugared() and this.isValidForSpecific(other))
or
private predicate isValidForSpecific0(AstNode n) {
this = n.(NonReturningCall).getACompletion()
or
completionIsValidForStmt(n, this)
@@ -110,12 +108,19 @@ abstract class Completion extends TCompletion {
or
n = any(RescueModifierExpr parent).getBody() and
this = [TSimpleCompletion().(TCompletion), TRaiseCompletion()]
}
private predicate isValidForSpecific(AstNode n) {
this.isValidForSpecific0(n)
or
exists(AstNode other | n = other.getDesugared() and this.isValidForSpecific(other))
or
mayRaise(n) and
(
this = TRaiseCompletion()
or
this = TSimpleCompletion() and not n instanceof NonReturningCall
not any(Completion c).isValidForSpecific0(n) and
this = TSimpleCompletion()
)
}

View File

@@ -6953,11 +6953,6 @@ raise.rb:
#-----| true -> [true] ... || ...
#-----| false -> b2
# 174| ... || ...
#-----| true -> 1
#-----| false -> 2
#-----| raise -> ExceptionA
# 174| [false] ... || ...
#-----| false -> 2
#-----| raise -> ExceptionA
@@ -6971,7 +6966,6 @@ raise.rb:
# 174| ... == ...
#-----| false -> [false] ... || ...
#-----| -> ... || ...
#-----| true -> [true] ... || ...
#-----| raise -> ExceptionA

View File

@@ -367,7 +367,6 @@ positionalArguments
| raise.rb:160:5:162:7 | call to bar | raise.rb:160:9:162:7 | -> { ... } |
| raise.rb:161:7:161:14 | call to raise | raise.rb:161:13:161:14 | "" |
| raise.rb:168:5:168:12 | call to raise | raise.rb:168:11:168:12 | "" |
| raise.rb:174:8:174:23 | ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
| raise.rb:174:8:174:23 | [false] ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
| raise.rb:174:8:174:23 | [true] ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
| raise.rb:174:14:174:23 | ... == ... | raise.rb:174:20:174:23 | true |