Merge pull request #545 from calumgrant/cs/typemention-constraints

C#: Fix for type mentions of type parameter constraints
This commit is contained in:
Tom Hvitved
2018-11-27 14:25:48 +01:00
committed by GitHub
3 changed files with 18 additions and 5 deletions

View File

@@ -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);
}
}
}
}

View File

@@ -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

View File

@@ -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 |