Bug 52340 - Compiler crashes with FATAL UNHANDLED EXCEPTION (nullref)
Summary: Compiler crashes with FATAL UNHANDLED EXCEPTION (nullref)
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 4.6.0 (C8)
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2017-02-06 23:10 UTC by shana@spoiledcat.net
Modified: 2017-02-15 16:20 UTC (History)
1 user (show)

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

stack trace (14.87 KB, text/plain)
2017-02-06 23:10 UTC, shana@spoiledcat.net

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:

Description shana@spoiledcat.net 2017-02-06 23:10:40 UTC
Created attachment 19741 [details]
stack trace

The following code crashes the compiler with a fatal unhandled exception. The nullable operator combined with Uri property return from the UriBuilder object triggers it (without both pieces, it doesn't crash).

> using System;
> class App
> {
> 	static void Main()
> 	{
> 		Uri url = null;
> 		var a = new UriBuilder
> 		{
> 			Port = url?.Port == 80 ? -1 : 1
> 		}.Uri;
> 	}
> }

> Mono.CSharp.InternalErrorException: compilercrash.cs(5,14): App.Main() ---> Mono.CSharp.InternalErrorException: compilercrash.cs(6,2): ---> System.NullReferenceException: Object reference not set to an instance of an object
>  at Mono.CSharp.InstanceEmitter.Emit (Mono.CSharp.EmitContext ec, System.Boolean conditionalAccess) [0x0016b] in <9494102539fd45149c591ed0d231421b>:0 
>  at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, System.Boolean statement, System.Nullable`1[T] loc) [0x000ef] in <9494102539fd45149c591ed0d231421b>:0 
>  at Mono.CSharp.CallEmitter.Emit (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Mono.CSharp.Location loc) [0x0000c] in <9494102539fd45149c591ed0d231421b>:0 

> Mono C# compiler version

> Mono JIT compiler version 4.6.2 (Stable Sun Jan  8 00:00:20 GMT 2017)
> Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
> 	TLS:           normal
> 	SIGSEGV:       altstack
> 	Notification:  kqueue
> 	Architecture:  amd64
> 	Disabled:      none
> 	Misc:          softdebug 
> 	LLVM:          supported, not enabled.
> 	GC:            sgen
Comment 1 Marek Safar 2017-02-15 13:43:06 UTC
Fixed in master
Comment 2 shana@spoiledcat.net 2017-02-15 16:20:43 UTC
Thanks Marek!