Skip to content

Commit 1a944ec

Browse files
committed
C#: Add some more tests for cs/coalesce-of-identical-expressions and update expected test output.
1 parent 9a2d8c2 commit 1a944ec

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

csharp/ql/test/query-tests/Language Abuse/UselessNullCoalescingExpression/UselessNullCoalescingExpression.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ void Main(int? param)
1212
a = param ?? param; // BAD
1313
a = a ?? use(a); // BAD
1414
a = Field ?? this.Field; // BAD
15+
a ??= a; // BAD
16+
a ??= b = a; // BAD
1517

1618
a = a ?? cache(ref a); // GOOD
1719
a = a ?? store(out a); // GOOD
@@ -23,6 +25,7 @@ void Main(int? param)
2325
?? a; // GOOD
2426
a = a ?? store(out a)
2527
?? a; // GOOD
28+
a ??= param; // GOOD
2629
}
2730

2831
int? cache(ref int? a)

csharp/ql/test/query-tests/Language Abuse/UselessNullCoalescingExpression/UselessNullCoalescingExpression.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
| UselessNullCoalescingExpression.cs:12:13:12:26 | ... ?? ... | Both operands of this null-coalescing expression access the same variable or property. |
55
| UselessNullCoalescingExpression.cs:13:13:13:23 | ... ?? ... | Both operands of this null-coalescing expression access the same variable or property. |
66
| UselessNullCoalescingExpression.cs:14:13:14:31 | ... ?? ... | Both operands of this null-coalescing expression access the same variable or property. |
7+
| UselessNullCoalescingExpression.cs:15:9:15:15 | ... ?? ... | Both operands of this null-coalescing expression access the same variable or property. |
8+
| UselessNullCoalescingExpression.cs:16:9:16:19 | ... ?? ... | Both operands of this null-coalescing expression access the same variable or property. |

0 commit comments

Comments
 (0)