Skip to content

Commit d4a3247

Browse files
committed
C#: No need to special-case default arguments in nullness analysis
1 parent 6c42418 commit d4a3247

2 files changed

Lines changed: 1 addition & 15 deletions

File tree

csharp/ql/lib/semmle/code/csharp/dataflow/Nullness.qll

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,6 @@ private predicate hasMultipleParamsArguments(Call c) {
181181
)
182182
}
183183

184-
private predicate isNullDefaultArgument(Ssa::ParameterDefinition def, AlwaysNullExpr arg) {
185-
exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p |
186-
p = def.getParameter()
187-
|
188-
p = pdef.getParameter().getUnboundDeclaration() and
189-
arg = p.getDefaultValue() and
190-
not arg.getEnclosingCallable().getEnclosingCallable*() instanceof TestMethod
191-
)
192-
}
193-
194184
/** Holds if `def` is an SSA definition that may be `null`. */
195185
private predicate defMaybeNull(Ssa::Definition def, ControlFlowNode node, string msg, Element reason) {
196186
not nonNullDef(def) and
@@ -216,10 +206,6 @@ private predicate defMaybeNull(Ssa::Definition def, ControlFlowNode node, string
216206
else msg = "because of $@ potential null argument"
217207
)
218208
or
219-
isNullDefaultArgument(def, reason) and
220-
node = def.getControlFlowNode() and
221-
msg = "because the parameter has a null default value"
222-
or
223209
// If the source of a variable is `null` then the variable may be `null`
224210
exists(AssignableDefinition adef | adef = def.(Ssa::ExplicitDefinition).getADefinition() |
225211
adef.getSource() = maybeNullExpr(node.asExpr()) and

csharp/ql/test/query-tests/Nullness/NullMaybe.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
| E.cs:302:9:302:9 | access to local variable s | Variable $@ may be null at this access because of $@ assignment. | E.cs:301:13:301:13 | s | s | E.cs:301:13:301:27 | String s = ... | this |
5353
| E.cs:343:9:343:9 | access to local variable x | Variable $@ may be null at this access because of $@ assignment. | E.cs:342:13:342:13 | x | x | E.cs:342:13:342:32 | String x = ... | this |
5454
| E.cs:349:9:349:9 | access to local variable x | Variable $@ may be null at this access because of $@ assignment. | E.cs:348:17:348:17 | x | x | E.cs:348:17:348:36 | dynamic x = ... | this |
55-
| E.cs:366:41:366:41 | access to parameter s | Variable $@ may be null at this access because the parameter has a null default value. | E.cs:366:28:366:28 | s | s | E.cs:366:32:366:35 | null | this |
55+
| E.cs:366:41:366:41 | access to parameter s | Variable $@ may be null at this access because of $@ assignment. | E.cs:366:28:366:28 | s | s | E.cs:366:32:366:35 | null | this |
5656
| E.cs:375:20:375:20 | access to local variable s | Variable $@ may be null at this access because of $@ assignment. | E.cs:374:17:374:17 | s | s | E.cs:374:17:374:31 | String s = ... | this |
5757
| E.cs:417:34:417:34 | access to parameter i | Variable $@ may be null at this access because it has a nullable type. | E.cs:415:27:415:27 | i | i | E.cs:415:27:415:27 | i | this |
5858
| E.cs:423:38:423:38 | access to parameter i | Variable $@ may be null at this access because it has a nullable type. | E.cs:420:27:420:27 | i | i | E.cs:420:27:420:27 | i | this |

0 commit comments

Comments
 (0)