Search code examples
c#csc

Why does C# compile this stack overflow error?


class ReferenceTest {
    public static string Status {
        get {
            return Status;
        }
    }
    public static void Main() {
        System.Console.WriteLine(Status);
    }
}

Is there any reason not to capture this loop at compilation time?


Solution

  • Just a missing heuristics. It's possible that you implement more complex logic in the getter, which would be too complex to analyze in the compile time. But static analyze tools like ReSharper are already warning about.