Skip to content

Commit 909e95f

Browse files
authored
Merge pull request #19782 from hvitved/csharp/type-arg-unique
C#: Handle non-unique type arguments when computing generics strings
2 parents 87b52cc + a188adc commit 909e95f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ private string getTypeArgumentsToString(ConstructedGeneric cg) {
110110
strictconcat(Type t, int i | t = cg.getTypeArgument(i) | t.toStringWithTypes(), ", " order by i)
111111
}
112112

113+
language[monotonicAggregates]
113114
pragma[nomagic]
114115
private string getTypeArgumentName(ConstructedGeneric cg, int i) {
115-
result = cg.getTypeArgument(i).getName()
116+
// Normally, `cg.getTypeArgument(i)` will be unique, and in those cases the line below
117+
// is simply the same as `result = cg.getTypeArgument(i).getName()`.
118+
result = strictconcat(Type t | t = cg.getTypeArgument(i) | t.getName(), "/")
116119
}
117120

118121
/** Gets the concatenation of the `getName()` of type arguments. */

csharp/ql/lib/semmle/code/csharp/commons/QualifiedName.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ module QualifiedName<QualifiedNameInputSig Input> {
4848
)
4949
}
5050

51+
language[monotonicAggregates]
5152
pragma[nomagic]
5253
private string getTypeArgumentsQualifiedName(ConstructedGeneric cg, int i) {
53-
result = getFullName(cg.getTypeArgument(i))
54+
// Normally, `cg.getTypeArgument(i)` will be unique, and in those cases the line below
55+
// is simply the same as `result = getFullName(cg.getTypeArgument(i))`.
56+
result = strictconcat(Type t | t = cg.getTypeArgument(i) | getFullName(t), "/")
5457
}
5558

5659
/** Gets the concatenation of the `getFullName` of type arguments. */

0 commit comments

Comments
 (0)