-1
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?

needfulthing
  • 1,056
  • 11
  • 21
  • The answer to why a feature is missing is simply that the designers of the compiler have not deemed the effort to add this worth it. I'd guess that once you handle the trivial cases like this one the less trivial ones would be expected to be handled and those are likely many magnitudes more difficult to deal with. – juharr Feb 16 '21 at 16:30
  • SO is not the appropriate place to propose new language features for C#. If you want to know why C# was designed the way that it was you'll need to ask the language designers. – Servy Feb 16 '21 at 16:30
  • Resharper catches this – Charlieface Feb 16 '21 at 20:44
  • I know this was a bit fuzzy. Actually I'm happy with a "No, this was just not respected." It's a really rare case to be able to produce such a loop without getting a warning. Normally CSC is quite picky, so I was astonished this simple code was able to sneak though compilation. Strangely I have the latest Resharper (with latest VS/Win10) and got no warning. – needfulthing Feb 17 '21 at 11:54

1 Answers1

0

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.

python_kaa
  • 1,034
  • 13
  • 27