Skip to content

Commit f3f3ee6

Browse files
committed
C#: Add cs/deferenced-value-is-always-null test example for compound operators.
1 parent 01baa6e commit f3f3ee6

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

csharp/ql/test/query-tests/Nullness/C.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,20 @@ public void Access()
264264
temp = sa.Length; // BAD (always), but not first
265265
}
266266

267+
public void CompoundAssignment()
268+
{
269+
C c1 = null;
270+
C c2 = new C(true);
271+
c1 += c2; // $ Alert[cs/dereferenced-value-is-always-null]
272+
}
273+
267274
bool m;
268275
C(bool m)
269276
{
270277
this.m = m;
271278
}
272279

273280
bool Maybe() => this.m;
281+
282+
public void operator +=(C other) { }
274283
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| C.cs:249:9:249:9 | access to local variable a | Variable $@ is always null at this dereference. | C.cs:248:15:248:15 | a | a |
2525
| C.cs:260:9:260:10 | access to local variable ia | Variable $@ is always null at this dereference. | C.cs:257:15:257:16 | ia | ia |
2626
| C.cs:261:20:261:21 | access to local variable sa | Variable $@ is always null at this dereference. | C.cs:258:18:258:19 | sa | sa |
27+
| C.cs:271:9:271:10 | access to local variable c1 | Variable $@ is always null at this dereference. | C.cs:269:11:269:12 | c1 | c1 |
2728
| D.cs:120:13:120:13 | access to local variable x | Variable $@ is always null at this dereference. | D.cs:117:13:117:13 | x | x |
2829
| D.cs:197:13:197:13 | access to local variable o | Variable $@ is always null at this dereference. | D.cs:195:13:195:13 | o | o |
2930
| D.cs:207:17:207:17 | access to local variable e | Variable $@ is always null at this dereference. | D.cs:204:26:204:26 | e | e |

0 commit comments

Comments
 (0)