Skip to content

Commit e4d4119

Browse files
committed
C#: Include store steps into readonly properties.
1 parent 3112bf4 commit e4d4119

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

csharp/ql/lib/semmle/code/csharp/Property.qll

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ class Property extends DotNet::Property, DeclarationWithGetSetAccessors, @proper
127127
properties(this, _, _, getTypeRef(result), _)
128128
}
129129

130+
private predicate isAutoPartial() {
131+
this.fromSource() and
132+
not this.isExtern() and
133+
not this.isAbstract() and
134+
not this.getAnAccessor().hasBody()
135+
}
136+
130137
/**
131138
* Holds if this property is automatically implemented. For example, `P1`
132139
* on line 2 is automatically implemented, while `P2` on line 5 is not in
@@ -147,11 +154,22 @@ class Property extends DotNet::Property, DeclarationWithGetSetAccessors, @proper
147154
* code.
148155
*/
149156
predicate isAutoImplemented() {
150-
this.fromSource() and
151-
this.isReadWrite() and
152-
not this.isExtern() and
153-
not this.isAbstract() and
154-
not this.getAnAccessor().hasBody()
157+
this.isAutoPartial() and
158+
this.isReadWrite()
159+
}
160+
161+
/**
162+
* Holds if this property is automatically implemented and read-only. For
163+
* example, `P1` on line 2 is automatically implemented and read-only
164+
* ```csharp
165+
* class C {
166+
* public int P1 { get; }
167+
* }
168+
* ```
169+
*/
170+
predicate isAutoImplementedReadOnly() {
171+
this.isAutoPartial() and
172+
this.isReadOnly()
155173
}
156174

157175
override Property getUnboundDeclaration() { properties(this, _, _, _, result) }

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,8 @@ class FieldOrProperty extends Assignable, Modifiable {
18991899
(
19001900
p.isAutoImplemented()
19011901
or
1902+
p.isAutoImplementedReadOnly()
1903+
or
19021904
p.matchesHandle(any(CIL::TrivialProperty tp))
19031905
or
19041906
p.getDeclaringType() instanceof AnonymousClass

0 commit comments

Comments
 (0)