Bug 52340

Summary: Compiler crashes with FATAL UNHANDLED EXCEPTION (nullref)
Product: [Mono] Compilers Reporter: shana <shana>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 4.6.0 (C8)   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: stack trace

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:
> Mono C# compiler version 4.6.2.0

> Mono JIT compiler version 4.6.2 (Stable 4.6.2.16/ac9e222 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!