mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
C#: Add extractor support for the notnull general type parameter constraint.
This commit is contained in:
@@ -40,6 +40,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
if (Symbol.ReferenceTypeConstraintNullableAnnotation == NullableAnnotation.Annotated)
|
||||
trapFile.general_type_parameter_constraints(this, 5);
|
||||
|
||||
if (Symbol.HasNotNullConstraint)
|
||||
trapFile.general_type_parameter_constraints(this, 6);
|
||||
|
||||
foreach (var abase in Symbol.GetAnnotatedTypeConstraints())
|
||||
{
|
||||
var t = Type.Create(Context, abase.Symbol);
|
||||
|
||||
@@ -287,6 +287,9 @@ class TypeParameterConstraints extends Element, @type_parameter_constraints {
|
||||
/** Holds if these constraints include a nullable reference type constraint. */
|
||||
predicate hasNullableRefTypeConstraint() { general_type_parameter_constraints(this, 5) }
|
||||
|
||||
/** Holds if these constraints include a not-null type constraint. */
|
||||
predicate hasNotNullTypeConstraint() { general_type_parameter_constraints(this, 6) }
|
||||
|
||||
/** Gets a textual representation of these constraints. */
|
||||
override string toString() { result = "where " + this.getTypeParameter().getName() + ": ..." }
|
||||
|
||||
|
||||
@@ -18,3 +18,5 @@ hasValueTypeConstraint
|
||||
hasUnmanagedTypeConstraint
|
||||
| TypeParameterConstraints.cs:10:20:10:21 | T3 | file://:0:0:0:0 | where T3: ... |
|
||||
hasNullableRefTypeConstraint
|
||||
hasNotNullConstraint
|
||||
| TypeParameterConstraints.cs:14:20:14:21 | T5 | file://:0:0:0:0 | where T5: ... |
|
||||
|
||||
@@ -29,3 +29,7 @@ query predicate hasUnmanagedTypeConstraint(TypeParameter tp, TypeParameterConstr
|
||||
query predicate hasNullableRefTypeConstraint(TypeParameter tp, TypeParameterConstraints tpc) {
|
||||
typeParameterContraints(tp, tpc) and tpc.hasNullableRefTypeConstraint()
|
||||
}
|
||||
|
||||
query predicate hasNotNullConstraint(TypeParameter tp, TypeParameterConstraints tpc) {
|
||||
typeParameterContraints(tp, tpc) and tpc.hasNotNullTypeConstraint()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user