Bug 20141 - C# async lambda causes compiler to crash.
Summary: C# async lambda causes compiler to crash.
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 3.4.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-05-29 11:10 UTC by bugzilla
Modified: 2014-05-30 09:27 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 2014-05-29 11:10:16 UTC
This code causes the C# compiler to crash.  I believe this is a regression as it only started happening today when I updated to Xamarin Studio 5.0 (not sure what the previous C# compiler version was, but the current version is now 3.4.0.0).

The problem seems to be related to the conversion of the "Dispose" method to a delegate.  If you change the "Action result" portion to "IDisposable result" and remove the ".Dispose" at the end of the statement, the code compiles just fine.

This is an excerpt of Program.cs from a new C# "Hello World" project (.NET 4.5) in Xamarin Studio.

class MainClass
{
	public static void Main(string [] args)
	{
		Action result = Subscribe(async token => {
			await Task.Yield();
		}).Dispose;
	}
	
	static IDisposable Subscribe(Func<CancellationToken,Task> subscribe)
	{
		throw new NotImplementedException();
	}
}

And here is the full error report:

Target CoreCompile:
		Tool /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/mcs.exe execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/x86/Debug/CSharpAsyncBug.exe Program.cs Properties/AssemblyInfo.cs obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /target:exe /define:DEBUG /nostdlib /platform:x86 /reference:/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/System.dll /reference:/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/System.Core.dll /reference:/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/mscorlib.dll /warn:4
Program.cs(11,11): warning CS0219: The variable `result' is assigned but its value is never used
		
		Unhandled Exception:
		Mono.CSharp.InternalErrorException: Program.cs(11,45): CSharpAsyncBug.MainClass.<Main>c__async1.MoveNext() ---> Mono.CSharp.InternalErrorException: (1,1): ---> System.ArgumentOutOfRangeException: Argument is out of range.
		Parameter name: index
		  at IKVM.Reflection.Emit.ILGenerator.MarkLabel (Label loc) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.EmitContext.MarkLabel (Label label) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AwaitStatement.EmitPrologue (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AwaitStatement.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Await.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.EmitEmbedded (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StateMachineInitializer.EmitMoveNext_NoResumePoints (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StateMachineInitializer.EmitMoveNext (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StateMachineInitializer+MoveNextBodyStatement.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StateMachineInitializer+MoveNextBodyStatement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  --- End of inner exception stack trace ---
		  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.MethodData.Emit (Mono.CSharp.TypeDefinition parent) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Method.Emit () [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.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(11,45): CSharpAsyncBug.MainClass.<Main>c__async1.MoveNext() ---> Mono.CSharp.InternalErrorException: (1,1): ---> System.ArgumentOutOfRangeException: Argument is out of range.
		Parameter name: index
		  at IKVM.Reflection.Emit.ILGenerator.MarkLabel (Label loc) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.EmitContext.MarkLabel (Label label) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AwaitStatement.EmitPrologue (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.AwaitStatement.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Await.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.EmitEmbedded (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StateMachineInitializer.EmitMoveNext_NoResumePoints (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StateMachineInitializer.EmitMoveNext (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StateMachineInitializer+MoveNextBodyStatement.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.StateMachineInitializer+MoveNextBodyStatement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  --- End of inner exception stack trace ---
		  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.MethodData.Emit (Mono.CSharp.TypeDefinition parent) [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0 
		  at Mono.CSharp.Method.Emit () [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.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.4.0/lib/mono/4.5/Microsoft.CSharp.targets: error : Compiler crashed with code: 1.
	Task "Csc" execution -- FAILED
Comment 1 Marek Safar 2014-05-30 09:24:59 UTC
I cannot reproduce the issue.

Tested with mono 3.4, 3.6 and master
Comment 2 Marek Safar 2014-05-30 09:27:07 UTC
Did more testing and I can reproduce the issue with 3.4 when async lambda statement is converted to expression.

However, the issue is not reproducible with master or 3.6