Typing the following code into a C# project causes VS to crash (stack overflow in the compiler).
class C
{
public static void Main(int arg)
{
int Local(int x = Local()) => 2;
}
}
I'm surprise it even compiles, as the default value part of the optional parameter requires a compile-time constant.
@AdamSpeight2008 It doesn't compile without an error. The compiler crashes before it has a chance to produce the error.
See https://github.com/dotnet/roslyn/pull/16315/files#r95429886 for a conversation that may be related to this.
@gafter I was saying that it shouldn't even compile. To me it sounds like it trying to see if the result of the default value is a constant, so it evaluates Local. And further down the rabbit hole we go.
@AdamSpeight2008 Agreed, it should not even compile. But the compiler should terminate nicely after printing a nice, friendly error message rather than crashing.
@gafter So is failing to parse? or Bind?
@AdamSpeight2008 Binding is failing in non-terminating recursion.
In essence, when Local is being bound to a symbol, it forces its parameters to be created and bound, meaning the default parameter is bound, which happens to be Local(), which means Local must be bound...
@agocke Randomly stumbled upon a skipped test due to this issue: LocalFunctionTests.RecursiveParameterDefault. Seems to be a dupe test of LocalFunctionTests.RecursiveDefaultParameter (which is not skipped), should probably remove it at some point.