14
duckWit
5y

Hours lost.

Visual Studio test adapter was failing out during the discover phase of the tests with a stack overflow exception, but that's all the information it gave me. The tests simply would not run.

Hunting through the code line by line, I eventually find this.

WHY IS THIS ALLOWED TO COMPILE

Comments
  • 0
    I assume it is because that is a statement, and should compile just fine, but fail at runtime.
  • 3
    @ewpratten right. The => is an expression-bodied member, and it gets converted by the compiler to a regular property with a defined getter. So it's basically a method calling itself, which is allowed, but it's a property calling itself, which makes me ask why I would ever want to do that. It seems to me like it's something the compiler could detect.
  • 4
    Maybe file an issue to the compiler devs and ask them to at least emit a warning when the compiler detects code like this https://github.com/dotnet/roslyn
  • 0
    Why? Well, it's just a recursive call. Perfectly legal but it will of course break if there's no way to stop the recursion.
Add Comment