-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C# 13: params modifier on collection types. #18329
base: main
Are you sure you want to change the base?
Conversation
ecced67
to
f4539f7
Compare
Copilot
AI
left a comment
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.
Copilot reviewed 13 out of 30 changed files in this pull request and generated 2 comments.
Files not reviewed (17)
- csharp/ql/lib/semmle/code/csharp/Callable.qll: Language not supported
- csharp/ql/lib/semmle/code/csharp/Variable.qll: Language not supported
- csharp/ql/lib/semmle/code/csharp/commons/Collections.qll: Language not supported
- csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll: Language not supported
- csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll: Language not supported
- csharp/ql/lib/semmle/code/csharp/frameworks/Format.qll: Language not supported
- csharp/ql/lib/semmle/code/csharp/frameworks/System.qll: Language not supported
- csharp/ql/lib/semmle/code/csharp/frameworks/system/collections/Generic.qll: Language not supported
- csharp/ql/test/library-tests/arguments/argumentByName.expected: Language not supported
- csharp/ql/test/library-tests/arguments/argumentByParameter.expected: Language not supported
- csharp/ql/test/library-tests/arguments/argumentByParameter.ql: Language not supported
- csharp/ql/test/library-tests/arguments/argumentName.expected: Language not supported
- csharp/ql/test/library-tests/arguments/argumentType.expected: Language not supported
- csharp/ql/test/library-tests/arguments/parameterGetArguments.expected: Language not supported
- csharp/ql/test/library-tests/arguments/parameterGetArguments.ql: Language not supported
- csharp/ql/test/library-tests/dispatch/CallContext.expected: Language not supported
- csharp/ql/test/library-tests/dispatch/GetADynamicTarget.expected: Language not supported
Tip: Leave feedback on Copilot's review comments with the 👎 and 👍 buttons to help improve review quality. Learn more
{ | ||
f10(0, 1, 2); | ||
f10(0, [1, 2]); | ||
f10(args: 1, o: 0); |
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.
The params modifier expects a List, but 1 is an int. It should be f10(args: new List { 1 }, o: 0);
f10(args: 1, o: 0); | |
f10(args: new List<int> { 1 }, o: 0); |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
SinkCollectionParams(new A()); // flow | ||
SinkCollectionParams(null, new A()); // flow | ||
SinkCollectionParams(null, new A(), null); // flow | ||
SinkCollectionParams([new A()]); // flow |
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.
The use of square brackets '[]' for collection initialization is incorrect in C#. It should be replaced with curly braces '{}'.
SinkCollectionParams([new A()]); // flow | |
SinkCollectionParams(new A[] { new A() }); // flow |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
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.
LGTM, added two minor comments.
abstract Type getElementType(); | ||
} | ||
|
||
private class AddArrayType extends ParamsCollectionTypeImpl instanceof ArrayType { |
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.
Why is this class named AddArrayType
? An alternative would be ParamsArrayType
.
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.
I have used the prefix Add
in other places for private classes, which only purpose is to populate (or add) elements to an abstract class. In any case, I don't have any strong preference :-)
override Type getElementType() { result = ArrayType.super.getElementType() } | ||
} | ||
|
||
private class AddCollectionTypes extends ParamsCollectionTypeImpl { |
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.
An alternative name could be ParamsConstructedCollectionTypes
?
…e the test reports indexer access and calls to Add for list and collection creations).
…s to allow ParamsCollectionType.
DCA looks good. |
fc22006
to
fe4ec59
Compare
In this PR we make the relevant updates to the CodeQL library to support collection like types for
params
parameters. The extractor worked out of the box for extracting these types.The feature is described here: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13#params-collections