Bug 28172

Summary: 3.12.1.
Product: [Mono] Compilers Reporter: Aaron Bockover [MSFT] <abock>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 3.12.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Test case

Description Aaron Bockover [MSFT] 2015-03-18 17:47:06 UTC
Created attachment 10403 [details]
Test case

Version: Mono JIT compiler version 3.12.1 ((detached/b63df7d Mon Mar 16 09:23:13 EDT 2015)
Package: MonoFramework-MDK-3.12.1.2.macos10.xamarin.x86.pkg

Given the method:

    static string GetFoo ()
    {
        return null;
    }

mcs crashes on the following expression:

    (GetFoo ()?.ToLower () ?? "bar").ToUpper ();

but works with the following:

    GetFoo ()?.ToLower () ?? "bar"

Stack trace:

Unhandled Exception:
Mono.CSharp.InternalErrorException: mcs-crash.cs(10,14): Crash.Main() ---> Mono.CSharp.InternalErrorException: mcs-crash.cs(11,2): ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Mono.CSharp.InstanceEmitter.Emit (Mono.CSharp.EmitContext ec, Boolean conditionalAccess) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Boolean statement, Nullable`1 loc) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CallEmitter.Emit (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Location loc) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodGroupExpr.EmitCall (Mono.CSharp.EmitContext ec, Mono.CSharp.Arguments arguments, Boolean statement) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Invocation.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Nullable.NullCoalescingOperator.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.InstanceEmitter.EmitLoad (Mono.CSharp.EmitContext ec, Boolean boxInstance) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.InstanceEmitter.Emit (Mono.CSharp.EmitContext ec, Boolean conditionalAccess) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Boolean statement, Nullable`1 loc) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CallEmitter.EmitStatement (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Location loc) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodGroupExpr.EmitCall (Mono.CSharp.EmitContext ec, Mono.CSharp.Arguments arguments, Boolean statement) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Invocation.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodData.Emit (Mono.CSharp.TypeDefinition parent) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeDefinition.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ClassOrStruct.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Class.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeDefinition.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ModuleContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AssemblyDefinition.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AssemblyDefinitionStatic.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: Mono.CSharp.InternalErrorException: mcs-crash.cs(10,14): Crash.Main() ---> Mono.CSharp.InternalErrorException: mcs-crash.cs(11,2): ---> System.NullReferenceException: Object reference not set to an instance of an object
  at Mono.CSharp.InstanceEmitter.Emit (Mono.CSharp.EmitContext ec, Boolean conditionalAccess) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Boolean statement, Nullable`1 loc) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CallEmitter.Emit (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Location loc) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodGroupExpr.EmitCall (Mono.CSharp.EmitContext ec, Mono.CSharp.Arguments arguments, Boolean statement) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Invocation.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Nullable.NullCoalescingOperator.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.InstanceEmitter.EmitLoad (Mono.CSharp.EmitContext ec, Boolean boxInstance) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.InstanceEmitter.Emit (Mono.CSharp.EmitContext ec, Boolean conditionalAccess) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CallEmitter.EmitPredefined (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Boolean statement, Nullable`1 loc) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CallEmitter.EmitStatement (Mono.CSharp.EmitContext ec, Mono.CSharp.MethodSpec method, Mono.CSharp.Arguments Arguments, Location loc) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodGroupExpr.EmitCall (Mono.CSharp.EmitContext ec, Mono.CSharp.Arguments arguments, Boolean statement) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Invocation.EmitStatement (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.StatementExpression.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ParametersBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodData.Emit (Mono.CSharp.TypeDefinition parent) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeDefinition.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ClassOrStruct.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Class.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeDefinition.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.NamespaceContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ModuleContainer.EmitContainer () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AssemblyDefinition.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AssemblyDefinitionStatic.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
Comment 1 Marek Safar 2015-04-02 09:25:59 UTC
Fixed in master and 4.0 mono