Skip to content

Commit b26c342

Browse files
committed
C#: Add extractor support for the allows ref struct general type parameter constraint.
1 parent a1db011 commit b26c342

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/TypeParameterConstraints.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public override void Populate(TextWriter trapFile)
4343
if (Symbol.HasNotNullConstraint)
4444
trapFile.general_type_parameter_constraints(this, 6);
4545

46+
if (Symbol.AllowsRefLikeType)
47+
trapFile.general_type_parameter_constraints(this, 7);
48+
4649
foreach (var abase in Symbol.GetAnnotatedTypeConstraints())
4750
{
4851
var t = Type.Create(Context, abase.Symbol);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ class TypeParameterConstraints extends Element, @type_parameter_constraints {
290290
/** Holds if these constraints include a not-null type constraint. */
291291
predicate hasNotNullTypeConstraint() { general_type_parameter_constraints(this, 6) }
292292

293+
/** Holds if these constraints include a `allows ref struct` constraint. */
294+
predicate hasAllowRefLikeTypeConstraint() { general_type_parameter_constraints(this, 7) }
295+
293296
/** Gets a textual representation of these constraints. */
294297
override string toString() { result = "where " + this.getTypeParameter().getName() + ": ..." }
295298

csharp/ql/test/library-tests/typeparameterconstraints/typeParameterConstraints.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ hasUnmanagedTypeConstraint
2020
hasNullableRefTypeConstraint
2121
hasNotNullConstraint
2222
| TypeParameterConstraints.cs:14:20:14:21 | T5 | file://:0:0:0:0 | where T5: ... |
23+
hasAllowRefLikeTypeConstraint
24+
| TypeParameterConstraints.cs:18:20:18:21 | T7 | file://:0:0:0:0 | where T7: ... |

csharp/ql/test/library-tests/typeparameterconstraints/typeParameterConstraints.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ query predicate hasNullableRefTypeConstraint(TypeParameter tp, TypeParameterCons
3333
query predicate hasNotNullConstraint(TypeParameter tp, TypeParameterConstraints tpc) {
3434
typeParameterContraints(tp, tpc) and tpc.hasNotNullTypeConstraint()
3535
}
36+
37+
query predicate hasAllowRefLikeTypeConstraint(TypeParameter tp, TypeParameterConstraints tpc) {
38+
typeParameterContraints(tp, tpc) and tpc.hasAllowRefLikeTypeConstraint()
39+
}

0 commit comments

Comments
 (0)