icsharpcode/ILSpy — Issue #296: Array initialization decompiles into recursive reference
Author: kevingadd
Created: 2011-12-02 07:05:10+00:00
State: open

Given the following code:

using System;

public static class Program {
public static void Main (string[] args) {
var cts = new CustomType[3];
cts[0] = new CustomType(1);
cts[1] = new CustomType(2.5f);
cts[2] = cts[0];
cts[0] *= 3;
cts[2].Value = 16;
Console.WriteLine("1={0}, 2={1}, 3={2}", cts[0], cts[1], cts[2]);
}
}

public struct CustomType {
public float Value;

public CustomType (float value) {
Value = value;
}

public static CustomType operator * (CustomType lhs, float rhs) {
return new CustomType(lhs.Value * rhs);
}

public override string ToString () {
return String.Format("{0}", Value);
}
}

ILSpy produces the following invalid initialization:
CustomType[] array = new CustomType[]
{
new CustomType(1f),
new CustomType(2.5f),
array[0]
};