-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C#: Handle non-unique type arguments when computing generics strings #19782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates QL utilities to use monotonic aggregates and strictconcat
when computing generic type argument strings, aiming to prevent combinatorial explosion for non-unique arguments.
- Enabled
language[monotonicAggregates]
for two helper functions - Replaced direct
getFullName
/getName
calls withstrictconcat
aggregators
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
csharp/ql/lib/semmle/code/csharp/commons/QualifiedName.qll | Added language[monotonicAggregates] and switched to strictconcat in getTypeArgumentsQualifiedName |
csharp/ql/lib/semmle/code/csharp/Generics.qll | Added language[monotonicAggregates] and switched to strictconcat in getTypeArgumentName |
Comments suppressed due to low confidence (2)
csharp/ql/lib/semmle/code/csharp/commons/QualifiedName.qll:54
- Using a
strictconcat
over a single-element generator tied toi
doesn’t aggregate across all type arguments, so it won’t prevent combinatorial explosion. Consider removing thei
parameter and aggregating overcg.getTypeArgument(*)
in one call or moving the aggregation into the caller.
result = strictconcat(Type t | t = cg.getTypeArgument(i) | getFullName(t), "/")
csharp/ql/lib/semmle/code/csharp/Generics.qll:116
- This
strictconcat
is also scoped to a singlei
, so you’re effectively concatenating only one element. To handle non-unique arguments correctly, aggregate over all arguments at once rather than indexing per call.
result = strictconcat(Type t | t = cg.getTypeArgument(i) | t.getName(), "/")
@@ -110,9 +110,10 @@ private string getTypeArgumentsToString(ConstructedGeneric cg) { | |||
strictconcat(Type t, int i | t = cg.getTypeArgument(i) | t.toStringWithTypes(), ", " order by i) | |||
} | |||
|
|||
language[monotonicAggregates] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add comments stating that this is merely a precaution and that we expect he concat to only concat a single name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
d61a674
to
a188adc
Compare
Avoids a combinatorial explosion when type arguments are not unique.