Skip to content

Commit de36151

Browse files
committed
C#: Add regression test and fix for type mentions of type parameter constraints.
1 parent 03fd549 commit de36151

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ public override void Populate()
3838
Context.Compilation.GetTypeByMetadataName(valueTypeName) :
3939
Context.Compilation.ObjectType;
4040

41-
var constraintTypes = new List<Type>();
4241
foreach (var abase in symbol.ConstraintTypes)
4342
{
4443
if (abase.TypeKind != TypeKind.Interface)
4544
baseType = abase;
4645
var t = Create(Context, abase);
4746
Context.Emit(Tuples.specific_type_parameter_constraints(constraints, t.TypeRef));
48-
constraintTypes.Add(t);
4947
}
5048

5149
Context.Emit(Tuples.types(this, Semmle.Extraction.Kinds.TypeKind.TYPE_PARAMETER, symbol.Name));
@@ -67,12 +65,15 @@ public override void Populate()
6765
clauses = clauses.Concat(declSyntaxReferences.OfType<ClassDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
6866
clauses = clauses.Concat(declSyntaxReferences.OfType<InterfaceDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
6967
clauses = clauses.Concat(declSyntaxReferences.OfType<StructDeclarationSyntax>().SelectMany(c => c.ConstraintClauses));
70-
int i = 0;
71-
foreach (var clause in clauses.Where(c => c.Name.ToString() == symbol.Name))
68+
foreach (var clause in clauses.Where(c => c.Name.Identifier.Text == symbol.Name))
7269
{
7370
TypeMention.Create(Context, clause.Name, this, this);
7471
foreach (var constraint in clause.Constraints.OfType<TypeConstraintSyntax>())
75-
TypeMention.Create(Context, constraint.Type, this, constraintTypes[i++]);
72+
{
73+
var ti = Context.Model(constraint).GetTypeInfo(constraint.Type);
74+
var target = Type.Create(Context, ti.Type);
75+
TypeMention.Create(Context, constraint.Type, this, target);
76+
}
7677
}
7778
}
7879
}

csharp/ql/test/library-tests/regressions/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,12 @@ class LocalVariableTags
139139
};
140140
}
141141

142+
partial class C1<T> where T: DynamicType
143+
{
144+
}
145+
146+
partial class C1<T> where T: DynamicType
147+
{
148+
}
149+
142150
// semmle-extractor-options: /r:System.Dynamic.Runtime.dll

csharp/ql/test/library-tests/regressions/TypeMentions.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@
6464
| Program.cs:135:33:135:38 | String |
6565
| Program.cs:135:41:135:46 | Object |
6666
| Program.cs:137:10:137:15 | Object |
67+
| Program.cs:142:27:142:27 | T |
68+
| Program.cs:142:30:142:40 | DynamicType |
69+
| Program.cs:146:27:146:27 | T |
70+
| Program.cs:146:30:146:40 | DynamicType |

0 commit comments

Comments
 (0)