mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
C#: Workaround Roslyn bug in INamedTypeSymbol.TupleElements
This commit is contained in:
@@ -24,7 +24,7 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
private TupleType(Context cx, INamedTypeSymbol init) : base(cx, init)
|
||||
{
|
||||
tupleElementsLazy = new Lazy<Field[]>(() => Symbol.TupleElements.Select(t => Field.Create(cx, t)).ToArray());
|
||||
tupleElementsLazy = new Lazy<Field[]>(() => Symbol.TupleElementsAdjusted().Select(t => Field.Create(cx, t)).ToArray());
|
||||
}
|
||||
|
||||
// All tuple types are "local types"
|
||||
|
||||
@@ -280,12 +280,18 @@ namespace Semmle.Extraction.CSharp
|
||||
private static void BuildFunctionPointerTypeId(this IFunctionPointerTypeSymbol funptr, Context cx, EscapingTextWriter trapFile, ISymbol symbolBeingDefined) =>
|
||||
BuildFunctionPointerSignature(funptr, trapFile, s => s.BuildOrWriteId(cx, trapFile, symbolBeingDefined));
|
||||
|
||||
/// <summary>
|
||||
/// Workaround for a Roslyn bug: https://github.com/dotnet/roslyn/issues/53943
|
||||
/// </summary>
|
||||
public static IEnumerable<IFieldSymbol> TupleElementsAdjusted(this INamedTypeSymbol type) =>
|
||||
type.TupleElements.Where(f => f is not null && f.Type is not null);
|
||||
|
||||
private static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, EscapingTextWriter trapFile, ISymbol symbolBeingDefined, bool constructUnderlyingTupleType)
|
||||
{
|
||||
if (!constructUnderlyingTupleType && named.IsTupleType)
|
||||
{
|
||||
trapFile.Write('(');
|
||||
trapFile.BuildList(",", named.TupleElements,
|
||||
trapFile.BuildList(",", named.TupleElementsAdjusted(),
|
||||
f =>
|
||||
{
|
||||
trapFile.Write((f.CorrespondingTupleField ?? f).Name);
|
||||
@@ -464,7 +470,7 @@ namespace Semmle.Extraction.CSharp
|
||||
trapFile.Write('(');
|
||||
trapFile.BuildList(
|
||||
",",
|
||||
namedType.TupleElements.Select(f => f.Type),
|
||||
namedType.TupleElementsAdjusted().Select(f => f.Type),
|
||||
t => t.BuildDisplayName(cx, trapFile));
|
||||
trapFile.Write(")");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user