Skip to content
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#] not requiring exact match for extension methods #5248

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

xavierpinho
Copy link
Contributor

In #5245, we resolved an extension method only if there was exactly one potential match, which deviates from the referenced source documentation, which states the resolution should target the first match found. However, it's not clear the order in which matches should be considered -- or, at least, I couldn't find it. Based on experimentation, it seems to prioritise the compile-time type, as can be seen in the tests involving MyConcrete and MyAbstract. To this end, I relaxed tryResolveExtensionMethodInvocation to always pick the 1st match.

In doing so, also uncovered a bug in which two methods can share the same methodFullName. We should disambiguate e.g. DoStuff(List<string>) from DoStuff<T>(List<T>). Included an ignored test, since it's not handled here. Once these are disambiguated, we can potentially start sorting the potential matches, based on their type signatures.

AST-wise, given how extension methods are static methods and we were already encoding x.Foo() as Foo(x), it seems like no further changes are required.

@xavierpinho xavierpinho added the c# Relates to csharpsrc2cpg label Jan 23, 2025
@xavierpinho xavierpinho merged commit 00d5d2c into master Jan 24, 2025
5 checks passed
@xavierpinho xavierpinho deleted the xavierp/c#-extension-methods-ctd branch January 24, 2025 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c# Relates to csharpsrc2cpg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants