mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
Merge pull request #545 from calumgrant/cs/typemention-constraints
C#: Fix for type mentions of type parameter constraints
This commit is contained in:
@@ -38,14 +38,12 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
Context.Compilation.GetTypeByMetadataName(valueTypeName) :
|
||||
Context.Compilation.ObjectType;
|
||||
|
||||
var constraintTypes = new List<Type>();
|
||||
foreach (var abase in symbol.ConstraintTypes)
|
||||
{
|
||||
if (abase.TypeKind != TypeKind.Interface)
|
||||
baseType = abase;
|
||||
var t = Create(Context, abase);
|
||||
Context.Emit(Tuples.specific_type_parameter_constraints(constraints, t.TypeRef));
|
||||
constraintTypes.Add(t);
|
||||
}
|
||||
|
||||
Context.Emit(Tuples.types(this, Semmle.Extraction.Kinds.TypeKind.TYPE_PARAMETER, symbol.Name));
|
||||
@@ -67,12 +65,15 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
clauses = clauses.Concat(declSyntaxReferences.OfType<ClassDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
|
||||
clauses = clauses.Concat(declSyntaxReferences.OfType<InterfaceDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
|
||||
clauses = clauses.Concat(declSyntaxReferences.OfType<StructDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
|
||||
int i = 0;
|
||||
foreach (var clause in clauses.Where(c => c.Name.ToString() == symbol.Name))
|
||||
foreach (var clause in clauses.Where(c => c.Name.Identifier.Text == symbol.Name))
|
||||
{
|
||||
TypeMention.Create(Context, clause.Name, this, this);
|
||||
foreach (var constraint in clause.Constraints.OfType<TypeConstraintSyntax>())
|
||||
TypeMention.Create(Context, constraint.Type, this, constraintTypes[i++]);
|
||||
{
|
||||
var ti = Context.Model(constraint).GetTypeInfo(constraint.Type);
|
||||
var target = Type.Create(Context, ti.Type);
|
||||
TypeMention.Create(Context, constraint.Type, this, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,4 +139,12 @@ class LocalVariableTags
|
||||
};
|
||||
}
|
||||
|
||||
partial class C1<T> where T: DynamicType
|
||||
{
|
||||
}
|
||||
|
||||
partial class C1<T> where T: DynamicType
|
||||
{
|
||||
}
|
||||
|
||||
// semmle-extractor-options: /r:System.Dynamic.Runtime.dll
|
||||
|
||||
@@ -64,3 +64,7 @@
|
||||
| Program.cs:135:33:135:38 | String |
|
||||
| Program.cs:135:41:135:46 | Object |
|
||||
| Program.cs:137:10:137:15 | Object |
|
||||
| Program.cs:142:27:142:27 | T |
|
||||
| Program.cs:142:30:142:40 | DynamicType |
|
||||
| Program.cs:146:27:146:27 | T |
|
||||
| Program.cs:146:30:146:40 | DynamicType |
|
||||
|
||||
Reference in New Issue
Block a user