-
Notifications
You must be signed in to change notification settings - Fork 226
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
VB.NET HasExactlyNArguments method considers null argument list and 0 arguments the same. #7458
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.
Let's delete some code. Try both variants to see the idea and choose what will seem nicer
analyzers/src/SonarAnalyzer.VisualBasic/Extensions/InvocationExpressionSyntaxExtensions.cs
Outdated
Show resolved
Hide resolved
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
? count == 0 | ||
: invocation.ArgumentList.Arguments.Count == count; |
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.
Whitespace
? count == 0 | |
: invocation.ArgumentList.Arguments.Count == count; | |
? count == 0 | |
: invocation.ArgumentList.Arguments.Count == count; |
@@ -30,7 +30,9 @@ internal static class InvocationExpressionSyntaxExtensions | |||
invocation.ArgumentList.Arguments.GetSymbolsOfKnownType(knownType, semanticModel); | |||
|
|||
internal static bool HasExactlyNArguments(this InvocationExpressionSyntax invocation, int count) => | |||
invocation?.ArgumentList != null && invocation.ArgumentList.Arguments.Count == count; | |||
invocation?.ArgumentList == null |
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.
Better null check
invocation?.ArgumentList == null | |
invocation?.ArgumentList is null |
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
In VB.NET a method can be called by invocation, for example,
d.Dispose()
, but it can be called also without the parentheses via member accessd.Dispose
.So having an argument list with 0 arguments and having no argument list at all is the same thing in VB.NET context.