Bug 25165

Summary: Bad code and async/await in a Task causes "Internal compiler error"
Product: [Mono] Compilers Reporter: Adam Patridge <patridge>
Component: C#Assignee: Marek Safar <masafa>
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Adam Patridge 2014-12-08 16:57:09 UTC
As I convert some legacy code to async/await and Tasks within some existing cruft, I ran into this error. It appears that an error my code is causing an "Internal compiler error" instead of revealing the actual build error I need to address.

    .../Program.cs(28,28): Error CS0584: Internal compiler error: Object reference not set to an instance of an object (CS0584) (SomeApp)

In the IDE, the hidden code error is indeed highlighted in red, so Source Analysis appears to be catching it correctly.

Here is a console app that recreates the issue.

	class MainClass
		public static void Main (string[] args)
			Console.WriteLine ("Hello World!");

			Task<Something> getSomething = (new TaskCompletionSource<Something> ()).Task;

			Task.Run (async () => {
				var something = await getSomething;
				if (something == null) {  // <-- "Internal compiler error"

				Console.WriteLine(something.Id); // <-- should be a build error instead (Id inaccessible)
	public class Something
		string Id { get; set; }

Commenting out that line removes the true build error, and it no longer has the internal compiler error.

	Task.Run (async () => {
		var something = await getSomething;
		if (something == null) { // <-- gets past here since build error is gone

Also, making the Task.Run Action synchronously will also remove the internal compiler error and reveal the true build error.

	Task.Run (() => {
		var something = new Something();
		if (something == null) {

		Console.WriteLine(something.Id); // <-- build error

Possibly related, though it seemed to affect an older version of Mono than I am using: https://bugzilla.xamarin.com/show_bug.cgi?id=22892

Xamarin Studio details:

> Xamarin Studio
> Version 5.5.4 (build 15)
> Installation UUID: 6fcde369-8230-488d-b74f-2c9b163b5a2f
> Runtime:
> 	Mono 3.10.0 ((detached/92c4884)
> 	GTK+ 2.24.23 (Raleigh theme)
> 	Package version: 310000031
Comment 1 Marek Safar 2014-12-10 09:08:19 UTC
Fixed in master