Roslyn: Compiler crash with recursive local function parameter default value

Created on 12 Jan 2017  路  9Comments  路  Source: dotnet/roslyn

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;
    }
}
4 - In Review Area-Compilers Bug New Language Feature - Local Functions Urgency-Soon

All 9 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marler8997 picture marler8997  路  3Comments

NikChao picture NikChao  路  3Comments

JesperTreetop picture JesperTreetop  路  3Comments

MadsTorgersen picture MadsTorgersen  路  3Comments

vbcodec picture vbcodec  路  3Comments