Skip to content

Commit 53c0880

Browse files
committed
C#: Improve the GetCallType method to also take extension operators into account.
1 parent 1c87cb3 commit 53c0880

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ type.SpecialType is SpecialType.System_IntPtr ||
234234
/// </summary>
235235
/// <param name="node">The expression syntax node.</param>
236236
/// <returns>Returns the target method symbol, or null if it cannot be resolved.</returns>
237-
protected IMethodSymbol? GetTargetSymbol(ExpressionSyntax node)
237+
protected static IMethodSymbol? GetTargetSymbol(Context cx, ExpressionSyntax node)
238238
{
239-
var si = Context.GetSymbolInfo(node);
239+
var si = cx.GetSymbolInfo(node);
240240
if (si.Symbol is ISymbol symbol)
241241
{
242242
var method = symbol as IMethodSymbol;
@@ -255,7 +255,7 @@ type.SpecialType is SpecialType.System_IntPtr ||
255255
.Where(method => method.Parameters.Length >= syntax.ArgumentList.Arguments.Count)
256256
.Where(method => method.Parameters.Count(p => !p.HasExplicitDefaultValue) <= syntax.ArgumentList.Arguments.Count);
257257

258-
return Context.ExtractionContext.IsStandalone ?
258+
return cx.ExtractionContext.IsStandalone ?
259259
candidates.FirstOrDefault() :
260260
candidates.SingleOrDefault();
261261
}
@@ -281,7 +281,7 @@ public static ExprKind UnaryOperatorKind(Context cx, ExprKind originalKind, Expr
281281
/// <param name="node">The expression.</param>
282282
public void AddOperatorCall(TextWriter trapFile, ExpressionSyntax node)
283283
{
284-
var @operator = GetTargetSymbol(node);
284+
var @operator = GetTargetSymbol(Context, node);
285285
if (@operator is IMethodSymbol method)
286286
{
287287
var callType = GetCallType(Context, node);
@@ -312,9 +312,9 @@ public enum CallType
312312
/// <returns>The call type.</returns>
313313
public static CallType GetCallType(Context cx, ExpressionSyntax node)
314314
{
315-
var @operator = cx.GetSymbolInfo(node);
315+
var @operator = GetTargetSymbol(cx, node);
316316

317-
if (@operator.Symbol is IMethodSymbol method)
317+
if (@operator is IMethodSymbol method)
318318
{
319319
if (method.ContainingSymbol is ITypeSymbol containingSymbol && containingSymbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Dynamic)
320320
{

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Invocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected override void PopulateExpression(TextWriter trapFile)
4444

4545
var child = -1;
4646
string? memberName = null;
47-
var target = GetTargetSymbol(Syntax);
47+
var target = GetTargetSymbol(Context, Syntax);
4848
switch (Syntax.Expression)
4949
{
5050
case MemberAccessExpressionSyntax memberAccess when IsValidMemberAccessKind():

0 commit comments

Comments
 (0)