-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C# 14: Support extension types.
#21220
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
Conversation
csharp/extractor/Semmle.Extraction.CSharp/CodeAnalysisExtensions/SymbolExtensions.cs
Fixed
Show fixed
Hide fixed
6218b5c to
5c44c08
Compare
csharp/extractor/Semmle.Extraction.CSharp/CodeAnalysisExtensions/SymbolExtensions.cs
Fixed
Show fixed
Hide fixed
…meter and make it possible to specify a parameter position offset.
a03f985 to
2a9166f
Compare
…tic generated methods with invocation of extension type member.
extension blocks.extension types.
2a9166f to
02e4a8b
Compare
|
@hvitved : The PR is ready for review. However, I haven't added any upgrade/downgrade scripts yet in case the review leads to a change in the DB scheme. Review on commit by commit basis is encouraged. |
hvitved
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.
Impressive work! Some mostly minor comments
csharp/extractor/Semmle.Extraction.CSharp/Entities/SyntheticExtensionParameter.cs
Outdated
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp/Entities/SyntheticExtensionParameter.cs
Outdated
Show resolved
Hide resolved
csharp/extractor/Semmle.Extraction.CSharp/CodeAnalysisExtensions/SymbolExtensions.cs
Outdated
Show resolved
Hide resolved
| - ["My.Qltest", "K", false, "GetMyFieldOnSyntheticField", "()", "", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField2].Field[My.Qltest.K.MyField]", "ReturnValue", "value", "manual"] | ||
| - ["My.Qltest", "Library", false, "SetValue", "(System.Object)", "", "Argument[0]", "Argument[this].SyntheticField[X]", "value", "dfc-generated"] | ||
| - ["My.Qltest", "Library", false, "GetValue", "()", "", "Argument[this].SyntheticField[X]", "ReturnValue", "value", "dfc-generated"] | ||
| - ["My.Qltest", "TestExtensions+extension(Object)", false, "Method1", "(System.Object)", "", "Argument[0]", "ReturnValue", "value", "manual"] |
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.
This ought to use the FQN of the type being extended, i.e. TestExtensions+extension(System.Object)
| catch | ||
| { | ||
| // If anything goes wrong, fall back to the unbound declaration. | ||
| return unboundDeclaration; | ||
| } |
Check notice
Code scanning / CodeQL
Generic catch clause Note
| if (parameter.Ordinal == 0) | ||
| { | ||
| if (parameter.ContainingSymbol is IMethodSymbol method && method.IsExtensionMethod) | ||
| { | ||
| return Parameter.Kind.This; | ||
| } | ||
| } |
Check notice
Code scanning / CodeQL
Nested 'if' statements can be combined Note
|
@hvitved Added some commits which addresses your comments, added DB upgrade/downgrade scripts (not intending to make the DB downgrade script delete all the extension members and types from the DB). Also made a minor modification to one of the QL4QL queries. |
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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
The last DCA run looks a bit skewed in terms of alert diff - this is most likely because one of the DCA variants for |
hvitved
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.
🎉
csharp/downgrades/178a7e6cf335486d33d4e49543148e3f57f04a9a/upgrade.properties
Outdated
Show resolved
Hide resolved
csharp/ql/lib/upgrades/68b5aec54e50fe7e375df3777b756a746ca3a37c/upgrade.properties
Outdated
Show resolved
Hide resolved
Co-authored-by: Tom Hvitved <hvitved@github.com>
In this PR we introduce support for
extensiontypes (blocks). The feature is explained in detail here.The feature generalises extensions to operators and properties.
Here is a small example of an declaration and how it can be invoked.
It turns out that Roslyn generates a static method corresponding to the extension method. To avoid extracting multiple methods with identical bodies (which would further complicate the QL implementation) we
IsValid()method, which has the qualified nameMyExtensions.extension(string).IsValid.stoIsValid()corresponding to the receiver parameters. This needs to be synthesised as we can't re-use the parameter from the extension declaration.MyExtensions.IsValidwithMyExtensions.extensions(string).IsValid.DCA looks good.
dotnet/runtimeproject. These extraction errors are because some of the extensions (that we now extract) adds user-defined compound assignment operators (described here), which are not supported yet.