Browse Source

Require System.ValueTuple to be a struct to be tuple compatible

C# only accepts System.ValueTuple as a tuple when it is a struct, so a class of
that name is an unrelated type and rendering it with tuple syntax describes it
as something it is not. It also made a tuple appear to contain itself, which no
struct can, and the deconstruction transform then registered the same variable
as a node of its tuple tree twice and threw ArgumentException, failing the whole
method instead of leaving the statements alone.

The check has accepted classes since tuples were added to the type system,
alongside a name comparison against "ValueType" that was corrected later.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
pull/3869/merge
Siegfried Pammer 1 month ago committed by Siegfried Pammer
parent
commit
a216586236
  1. 3
      ICSharpCode.Decompiler/TypeSystem/TupleType.cs

3
ICSharpCode.Decompiler/TypeSystem/TupleType.cs

@ -115,8 +115,9 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -115,8 +115,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
case TypeKind.Tuple:
tupleCardinality = ((TupleType)type).ElementTypes.Length;
return true;
case TypeKind.Class:
case TypeKind.Struct:
// C# requires System.ValueTuple to be a struct, so a class of that name is
// some other type that happens to share it and must not become tuple syntax.
if (type.Namespace == "System" && type.Name == "ValueTuple")
{
int tpc = type.TypeParameterCount;

Loading…
Cancel
Save