Summary
Decompiling a foreach over an inline array value produces code that does not compile: it references the compiler-internal <PrivateImplementationDetails>.InlineArrayElementRef helper, whose type name contains angle brackets and cannot be written in C#.
Steps to reproduce
Compile this with an optimizing compiler:
using System.Runtime.CompilerServices;
[InlineArray(4)]
public struct Buf4 { private int _element0; }
public static class C
{
public static int Sum(Buf4 b)
{
int s = 0;
foreach (int x in b) s += x;
return s;
}
}
Decompile type C.
Actual output
public static int Sum(Buf4 b)
{
int num = 0;
for (int i = 0; i < 4; i++)
{
int num2 = global::<PrivateImplementationDetails>.InlineArrayElementRef<Buf4, int>(ref b, i);
num += num2;
}
return num;
}
This does not compile (error CS1001: Identifier expected at global::<PrivateImplementationDetails>). <PrivateImplementationDetails> is a compiler-generated type and InlineArrayElementRef<TBuffer, TElement> is a helper the compiler emits there to lower foreach over an inline-array value; the decompiler does not recognize the pattern and emits the raw call.
Expected output
Valid C# equivalent to the source, e.g. reconstructing the loop via the inline-array indexer:
public static int Sum(Buf4 b)
{
int num = 0;
for (int i = 0; i < 4; i++)
{
num += b[i];
}
return num;
}
(or the original foreach).
Scope
- Specific to
foreach over an inline array. Other inline-array patterns decompile correctly: direct indexing (b[0]), for with the indexer, index-from-end (b[^1]), range/slice (b[1..4]), implicit Span<T> conversion, ref-to-element, passing as a span, and inline-array fields.
- Not currently covered by
InlineArrayTests.
Version
ICSharpCode.Decompiler: 11.0.0 (current master).
This issue was filed by an AI agent (Claude, claude-opus-4-8, via Claude Code) on behalf of the repo owner.
Summary
Decompiling a
foreachover an inline array value produces code that does not compile: it references the compiler-internal<PrivateImplementationDetails>.InlineArrayElementRefhelper, whose type name contains angle brackets and cannot be written in C#.Steps to reproduce
Compile this with an optimizing compiler:
Decompile type
C.Actual output
This does not compile (
error CS1001: Identifier expectedatglobal::<PrivateImplementationDetails>).<PrivateImplementationDetails>is a compiler-generated type andInlineArrayElementRef<TBuffer, TElement>is a helper the compiler emits there to lowerforeachover an inline-array value; the decompiler does not recognize the pattern and emits the raw call.Expected output
Valid C# equivalent to the source, e.g. reconstructing the loop via the inline-array indexer:
(or the original
foreach).Scope
foreachover an inline array. Other inline-array patterns decompile correctly: direct indexing (b[0]),forwith the indexer, index-from-end (b[^1]), range/slice (b[1..4]), implicitSpan<T>conversion, ref-to-element, passing as a span, and inline-array fields.InlineArrayTests.Version
ICSharpCode.Decompiler: 11.0.0(current master).This issue was filed by an AI agent (Claude, claude-opus-4-8, via Claude Code) on behalf of the repo owner.