Bug 25165 - Bad code and async/await in a Task causes "Internal compiler error"
Summary: Bad code and async/await in a Task causes "Internal compiler error"
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-12-08 16:57 UTC by Adam Patridge
Modified: 2014-12-10 09:08 UTC (History)
1 user (show)

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


Attachments

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"
					return;
				}

				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
			return;
		}
	});

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) {
			return;
		}

		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

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.


Create a new report for Bug 25165 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments


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.

Related Links: