Skip to content

Commit 260ce80

Browse files
committed
C#: Also support implicit inherited ToString synthetic calls.
1 parent ec256c3 commit 260ce80

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@ internal sealed class ImplicitToString : Expression
1414
/// </summary>
1515
private static IMethodSymbol? GetToStringMethod(ITypeSymbol? type)
1616
{
17-
return type?
17+
if (type is null)
18+
{
19+
return null;
20+
}
21+
22+
var toString = type
1823
.GetMembers()
1924
.OfType<IMethodSymbol>()
2025
.Where(method =>
2126
method.GetName() == "ToString" &&
2227
method.Parameters.Length == 0
2328
)
2429
.FirstOrDefault();
30+
31+
return toString ?? GetToStringMethod(type.BaseType);
2532
}
2633

2734
private ImplicitToString(ExpressionNodeInfo info, IMethodSymbol toString) : base(new ExpressionInfo(info.Context, AnnotatedTypeSymbol.CreateNotAnnotated(toString.ReturnType), info.Location, ExprKind.METHOD_INVOCATION, info.Parent, info.Child, isCompilerGenerated: true, info.ExprValue))

0 commit comments

Comments
 (0)