Bug 13793 - Error CS0584: Internal compiler error: Object reference not set to an instance of an object (CS0584)
Summary: Error CS0584: Internal compiler error: Object reference not set to an instanc...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-08-06 20:32 UTC by Kirk Woll
Modified: 2015-04-13 10:33 UTC (History)
2 users (show)

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


Attachments
Sample application (59 bytes, text/plain)
2015-04-13 10:30 UTC, Mathieu Clerici
Details


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 Kirk Woll 2013-08-06 20:32:23 UTC
The following code will crash the compiler:

/Users/kirk/Projects/CompilerErrorDefaultParametersAndGenerics/AppDelegate.cs(13,13): Error CS0584: Internal compiler error: Object reference not set to an instance of an object (CS0584) (CompilerErrorDefaultParametersAndGenerics)

    public class AppDelegate()
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            M(1);
        }

        public static void M<T>(T item1, T item2 = null) where T : class
        {
        }
    }

Now, the code above *is* illegal -- we are passing a value type despite the generic constraint "where T : class".  However, I would expect a compiler error message to that effect, rather than the compiler crashing.  Removing "where T : class" will also crash the compiler, but it will at least additionally provide the error message:

/Users/kirk/Projects/CompilerErrorDefaultParametersAndGenerics/AppDelegate.cs(52,52): Error CS1750: Optional parameter expression of type `null' cannot be converted to parameter type `T' (CS1750) (CompilerErrorDefaultParametersAndGenerics)
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-08-07 05:32:41 UTC
A bit smaller test case:

class Program {
    public static void M<T>(T item1, T item2 = null) where T : class
    {
    	M(1);
    }
}
Comment 2 Marek Safar 2013-08-07 09:19:36 UTC
Fixed in master
Comment 3 Mathieu Clerici 2015-04-13 10:30:44 UTC
Created attachment 10735 [details]
Sample application