Skip to content

Commit dab3ac6

Browse files
committed
C#: Add struct example to test for cs/missing-readonly-modifier.
1 parent 3a1cd3f commit dab3ac6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class MissedReadonlyOpportunity<T>
88
public int Good4;
99
public readonly T Good5;
1010
public T Good6;
11+
public Mutable Good7;
1112

1213
public MissedReadonlyOpportunity(int i, T t)
1314
{
@@ -18,6 +19,7 @@ public MissedReadonlyOpportunity(int i, T t)
1819
Good4 = i;
1920
Good5 = t;
2021
Good6 = t;
22+
Good7 = new Mutable();
2123
}
2224

2325
public void M(int i)
@@ -27,3 +29,13 @@ public void M(int i)
2729
x.Good6 = false;
2830
}
2931
}
32+
33+
struct Mutable
34+
{
35+
private int x;
36+
public int Mutate()
37+
{
38+
x = x + 1;
39+
return x;
40+
}
41+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#select
12
| MissedReadonlyOpportunity.cs:3:16:3:19 | Bad1 | Field 'Bad1' can be 'readonly'. |
23
| MissedReadonlyOpportunity.cs:4:14:4:17 | Bad2 | Field 'Bad2' can be 'readonly'. |
4+
| MissedReadonlyOpportunity.cs:11:20:11:24 | Good7 | Field 'Good7' can be 'readonly'. |
35
| MissedReadonlyOpportunityBad.cs:3:9:3:13 | Field | Field 'Field' can be 'readonly'. |
6+
testFailures
7+
| MissedReadonlyOpportunity.cs:11:20:11:24 | Field 'Good7' can be 'readonly'. | Unexpected result: Alert |

0 commit comments

Comments
 (0)