Skip to content

Commit 692d703

Browse files
committed
C#: Add extractor and QL library support for ref readonly parameters.
1 parent a86de9d commit 692d703

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/CachedSymbol.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected void PopulateRefKind(TextWriter trapFile, RefKind kind)
5353
trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
5454
break;
5555
case RefKind.RefReadOnly:
56+
case RefKind.RefReadOnlyParameter:
5657
trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef);
5758
break;
5859
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ protected Parameter(Context cx, IParameterSymbol init, IEntity? parent, Paramete
2424

2525
public enum Kind
2626
{
27-
None, Ref, Out, Params, This, In
27+
None = 0,
28+
Ref = 1,
29+
Out = 2,
30+
Params = 3,
31+
This = 4,
32+
In = 5,
33+
RefReadOnly = 6
2834
}
2935

3036
protected virtual int Ordinal => Symbol.Ordinal;
@@ -41,6 +47,8 @@ private Kind ParamKind
4147
return Kind.Ref;
4248
case RefKind.In:
4349
return Kind.In;
50+
case RefKind.RefReadOnlyParameter:
51+
return Kind.RefReadOnly;
4452
default:
4553
if (Symbol.IsParams)
4654
return Kind.Params;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ class Parameter extends DotNet::Parameter, LocalScopeVariable, Attributable, Top
167167
*/
168168
predicate isParams() { params(this, _, _, _, 3, _, _) }
169169

170+
/**
171+
* Holds if this parameter if a ref readonly parameter.
172+
* For example, `p` is a ref readonly parameter in
173+
*
174+
* ```csharp
175+
* void M(ref readonly int p) {
176+
* ...
177+
* }
178+
* ```
179+
*/
180+
predicate isReadonlyRef() { params(this, _, _, _, 6, _, _) }
181+
170182
/**
171183
* Holds this parameter is the first parameter of an extension method.
172184
* For example, `list` is the first parameter of the extension method

0 commit comments

Comments
 (0)