File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
csharp/ql/test/query-tests/Language Abuse/MissedReadonlyOpportunity Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -39,3 +39,42 @@ public int Mutate()
3939 return x ;
4040 }
4141}
42+
43+ class Tree
44+ {
45+ private Tree ? Parent ;
46+ private Tree ? Left ; // $ Alert
47+ private readonly Tree ? Right ;
48+
49+ public Tree ( Tree left , Tree right )
50+ {
51+ this . Left = left ;
52+ this . Right = right ;
53+ left . Parent = this ;
54+ right . Parent = this ;
55+ }
56+
57+ public Tree ( )
58+ {
59+ Left = null ;
60+ Right = null ;
61+ }
62+ }
63+
64+ class StaticFields
65+ {
66+ static int X ; // $ Alert
67+ static int Y ;
68+
69+ // Static constructor
70+ static StaticFields ( )
71+ {
72+ X = 0 ;
73+ }
74+
75+ // Instance constructor
76+ public StaticFields ( int y )
77+ {
78+ Y = y ;
79+ }
80+ }
Original file line number Diff line number Diff line change 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:45:19:45:24 | Parent | Field 'Parent' can be 'readonly'. |
5+ | MissedReadonlyOpportunity.cs:46:19:46:22 | Left | Field 'Left' can be 'readonly'. |
6+ | MissedReadonlyOpportunity.cs:66:16:66:16 | X | Field 'X' can be 'readonly'. |
7+ | MissedReadonlyOpportunity.cs:67:16:67:16 | Y | Field 'Y' can be 'readonly'. |
38| MissedReadonlyOpportunityBad.cs:3:9:3:13 | Field | Field 'Field' can be 'readonly'. |
9+ testFailures
10+ | MissedReadonlyOpportunity.cs:45:19:45:24 | Field 'Parent' can be 'readonly'. | Unexpected result: Alert |
11+ | MissedReadonlyOpportunity.cs:67:16:67:16 | Field 'Y' can be 'readonly'. | Unexpected result: Alert |
You can’t perform that action at this time.
0 commit comments