Skip to content

Commit a3d74b0

Browse files
committed
C#: Address review comments
1 parent a683990 commit a3d74b0

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

change-notes/1.19/analysis-csharp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* Control flow graph improvements:
66
* The control flow graph construction now takes simple Boolean conditions on local scope variables into account. For example, in `if (b) x = 0; if (b) x = 1;`, the control flow graph will reflect that taking the `true` (resp. `false`) branch in the first condition implies taking the same branch in the second condition. In effect, the first assignment to `x` will now be identified as being dead.
7-
* Constant failing assertions, such as `Debug.Assert(false)`, are now taken into account. Syntactic successors of constant failing assertions are consequently dead code.
7+
* Code that is only reachable from a constant failing assertion, such as `Debug.Assert(false)`, is considered to be unreachable.
88

99
## New queries
1010

csharp/ql/src/semmle/code/csharp/commons/Assertions.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class AssertMethod extends Method {
99
abstract int getAssertionIndex();
1010

1111
/** Gets the parameter being asserted. */
12-
final Parameter getAssertionParameter() {
12+
final Parameter getAssertedParameter() {
1313
result = this.getParameter(this.getAssertionIndex())
1414
}
1515

@@ -44,7 +44,7 @@ class Assertion extends MethodCall {
4444

4545
/** Gets the expression that this assertion pertains to. */
4646
Expr getExpr() {
47-
result = this.getArgumentForParameter(target.getAssertionParameter())
47+
result = this.getArgumentForParameter(target.getAssertedParameter())
4848
}
4949
}
5050

@@ -55,10 +55,10 @@ class FailingAssertion extends Assertion {
5555
am = this.getAssertMethod() and
5656
e = this.getExpr() |
5757
am instanceof AssertTrueMethod and
58-
e.(BoolLiteral).getBoolValue() = false
58+
e.getValue() = "false"
5959
or
6060
am instanceof AssertFalseMethod and
61-
e.(BoolLiteral).getBoolValue() = true
61+
e.getValue() = "true"
6262
)
6363
}
6464
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import csharp
22

3-
class Stub extends File {
4-
Stub() {
3+
class StubFile extends File {
4+
StubFile() {
55
this.getAbsolutePath().matches("%resources/stubs/%")
66
}
77
}
88

99
class SourceControlFlowElement extends ControlFlowElement {
1010
SourceControlFlowElement() {
11-
not this.getLocation().getFile() instanceof Stub
11+
not this.getLocation().getFile() instanceof StubFile
1212
}
1313
}
1414

1515
class SourceControlFlowNode extends ControlFlow::Node {
1616
SourceControlFlowNode() {
17-
not this.getLocation().getFile() instanceof Stub
17+
not this.getLocation().getFile() instanceof StubFile
1818
}
1919
}
2020

2121
class SourceBasicBlock extends ControlFlow::BasicBlock {
2222
SourceBasicBlock() {
23-
not this.getLocation().getFile() instanceof Stub
23+
not this.getLocation().getFile() instanceof StubFile
2424
}
2525
}

0 commit comments

Comments
 (0)