Bug 26736 - C# async lambda with nested lambda and "goto" statement causes compiler to crash.
Summary: C# async lambda with nested lambda and "goto" statement causes compiler to cr...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-02-04 11:08 UTC by bugzilla
Modified: 2015-02-06 09:14 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description bugzilla 2015-02-04 11:08:44 UTC
This code causes the C# compiler to crash.  You should be able to just paste the code into the Program.cs file of a new Console application in Xamarin Studio.  It seems to be the combination of the variable declaration statement within the async lambda which constructs a nested lambda, combined with the use of a "goto" statement below it.  The code compiles without error if the variable declaration statement is removed, or if the "goto" statement is changed to a "while" statement.

I am using Mono 3.12.0 (detached/a813491) on OS/X Yosemite 10.10.2.

(P.S. "3.12.0" is not in the version list displayed in the bugzilla.xamarin.com "new bug" form)

using System;
using System.Threading.Tasks;

namespace AsyncGotoBug
{
    class MainClass
    {
        public static void Main(string [] args)
        {
            SomeMethod(async () => {
                Func<int,int> f = b => b;
                retry:
                await Task.Yield();
                goto retry;
            });
        }
        
        static void SomeMethod(Action a)
        {
        }
    }
}

Here is the full error output:

Tool /Library/Frameworks/Mono.framework/Versions/3.12.0/lib/mono/4.5/mcs.exe execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/x86/Debug/AsyncGotoBug.exe Program.cs Properties/AssemblyInfo.cs /target:exe /define:DEBUG /nostdlib /platform:x86 /reference:/Library/Frameworks/Mono.framework/Versions/3.12.0/lib/mono/4.5/System.dll /reference:/Library/Frameworks/Mono.framework/Versions/3.12.0/lib/mono/4.5/System.Core.dll /reference:/Library/Frameworks/Mono.framework/Versions/3.12.0/lib/mono/4.5/mscorlib.dll /warn:4
		
		Unhandled Exception:
		Mono.CSharp.InternalErrorException: Program.cs(8,22): AsyncGotoBug.MainClass.Main(string[]) ---> System.ArgumentOutOfRangeException: Argument is out of range.
		Parameter name: index
		  at Mono.CSharp.ParametersBlock.RemapLabeledStatement (Mono.CSharp.LabeledStatement stmt, Mono.CSharp.Block src, Mono.CSharp.Block dst) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Statement.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.CloneContext.LookupBlock (Mono.CSharp.Block from) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AnonymousMethodExpression.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Expression t) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.BlockVariable.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement target) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Statement.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Block.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Statement.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.PerformClone () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AnonymousMethodExpression.CompatibleMethodBody (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeInferenceContext tic, Mono.CSharp.TypeSpec return_type, Mono.CSharp.TypeSpec delegate_type) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AnonymousMethodExpression.Compatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec type) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AnonymousMethodExpression.ImplicitStandardConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec delegate_type) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Convert.ImplicitConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression expr, Mono.CSharp.TypeSpec target_type) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.OverloadResolver.IsArgumentCompatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.Argument argument, Modifier param_mod, Mono.CSharp.TypeSpec parameter) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.OverloadResolver.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, Mono.CSharp.MemberSpec& candidate, IParametersMember pm, System.Boolean& params_expanded_form, System.Boolean& dynamicArgument, Mono.CSharp.TypeSpec& returnType, Boolean errorMode) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.OverloadResolver.ResolveMember[MethodSpec] (Mono.CSharp.ResolveContext rc, Mono.CSharp.Arguments& args) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& args, IErrorHandler cerrors, Restrictions restr) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Invocation.DoResolveInvocation (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext rc) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 
		  --- End of inner exception stack trace ---
		  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeDefinition.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ClassOrStruct.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Class.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeDefinition.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ModuleContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AssemblyDefinition.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AssemblyDefinitionStatic.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 
		[ERROR] FATAL UNHANDLED EXCEPTION: Mono.CSharp.InternalErrorException: Program.cs(8,22): AsyncGotoBug.MainClass.Main(string[]) ---> System.ArgumentOutOfRangeException: Argument is out of range.
		Parameter name: index
		  at Mono.CSharp.ParametersBlock.RemapLabeledStatement (Mono.CSharp.LabeledStatement stmt, Mono.CSharp.Block src, Mono.CSharp.Block dst) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Statement.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.CloneContext.LookupBlock (Mono.CSharp.Block from) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AnonymousMethodExpression.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Expression t) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Expression.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.BlockVariable.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement target) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Statement.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Block.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.CloneTo (Mono.CSharp.CloneContext clonectx, Mono.CSharp.Statement t) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Statement.Clone (Mono.CSharp.CloneContext clonectx) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.PerformClone () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AnonymousMethodExpression.CompatibleMethodBody (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeInferenceContext tic, Mono.CSharp.TypeSpec return_type, Mono.CSharp.TypeSpec delegate_type) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AnonymousMethodExpression.Compatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec type) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AnonymousMethodExpression.ImplicitStandardConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.TypeSpec delegate_type) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Convert.ImplicitConversionExists (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression expr, Mono.CSharp.TypeSpec target_type) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.OverloadResolver.IsArgumentCompatible (Mono.CSharp.ResolveContext ec, Mono.CSharp.Argument argument, Modifier param_mod, Mono.CSharp.TypeSpec parameter) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.OverloadResolver.IsApplicable (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, Mono.CSharp.MemberSpec& candidate, IParametersMember pm, System.Boolean& params_expanded_form, System.Boolean& dynamicArgument, Mono.CSharp.TypeSpec& returnType, Boolean errorMode) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.OverloadResolver.ResolveMember[MethodSpec] (Mono.CSharp.ResolveContext rc, Mono.CSharp.Arguments& args) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& args, IErrorHandler cerrors, Restrictions restr) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Invocation.DoResolveInvocation (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext rc) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 
		  --- End of inner exception stack trace ---
		  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeDefinition.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ClassOrStruct.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Class.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeDefinition.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ModuleContainer.EmitContainer () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AssemblyDefinition.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AssemblyDefinitionStatic.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 
/Library/Frameworks/Mono.framework/Versions/3.12.0/lib/mono/4.5/Microsoft.CSharp.targets: error : Compiler crashed with code: 1.
	Task "Csc" execution -- FAILED
Comment 1 Marek Safar 2015-02-06 09:14:48 UTC
Fixed in master