Bug 30695 - Invalid syntax (using ?.) crashes smcs
Summary: Invalid syntax (using ?.) crashes smcs
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 4.0.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-06-02 19:18 UTC by Darrel
Modified: 2015-06-03 06:06 UTC (History)
1 user (show)

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

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 Darrel 2015-06-02 19:18:31 UTC
** The following code crashes the compiler:

namespace MyCompany.MyProject
{
    public class Module
    {
        public class Test1
        {
            public class Test2
            {
                public System.EventHandler<System.EventArgs> E;
            }

            public Test2 test2 = new Test2();
        }

        static void Main() {
            new Test1()?.test2.E += (s, a) => { };
        }
    }
}


** Output

    Unhandled Exception:
    Mono.CSharp.InternalErrorException: MyCompany/MyProject/Main.cs(15,21): MyCompany/MyProject.Module.Main() ---> Mono.CSharp.InternalErrorException: MyCompany/MyProject/Main.cs(15,28): ---> System.NullReferenceException: Object reference not set to an instance of an object
      at Mono.CSharp.EmitContext.CloseConditionalAccess (Mono.CSharp.TypeSpec type) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.FieldExpr.Emit (Mono.CSharp.EmitContext ec, Boolean leave_copy) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.FieldExpr.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.CompoundAssign+TargetExpression.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.Argument.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.Arguments.Emit (Mono.CSharp.EmitContext ec, Boolean dup_args, Boolean prepareAwait) [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.UserOperatorCall.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.TypeCast.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.ClassCast.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.FieldExpr.EmitAssign (Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean leave_copy, Boolean isCompound) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.Assign.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.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: MyCompany/MyProject/Main.cs(15,21): MyCompany/MyProject.Module.Main() ---> Mono.CSharp.InternalErrorException: MyCompany/MyProject/Main.cs(15,28): ---> System.NullReferenceException: Object reference not set to an instance of an object
      at Mono.CSharp.EmitContext.CloseConditionalAccess (Mono.CSharp.TypeSpec type) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.FieldExpr.Emit (Mono.CSharp.EmitContext ec, Boolean leave_copy) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.FieldExpr.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.CompoundAssign+TargetExpression.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.Argument.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.Arguments.Emit (Mono.CSharp.EmitContext ec, Boolean dup_args, Boolean prepareAwait) [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.UserOperatorCall.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.TypeCast.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.ClassCast.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.FieldExpr.EmitAssign (Mono.CSharp.EmitContext ec, Mono.CSharp.Expression source, Boolean leave_copy, Boolean isCompound) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.Assign.Emit (Mono.CSharp.EmitContext ec, Boolean is_statement) [0x00000] in <filename unknown>:0 
      at Mono.CSharp.Assign.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.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 

---------------------- Done ----------------------

Build: 1 error, 0 warnings


** System

Xamarin Studio
Version 5.9.2 (build 4)
Installation UUID: 720d08f3-5c6d-4728-9c99-c0fe8b378c8b
Runtime:
	Mono 4.0.1 ((detached/ed1d3ec)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010044

Xamarin.Android
Not Installed

Xamarin Android Player
Not Installed

Apple Developer Tools
Xcode 6.3.2 (7718)
Build 6D2105

Xamarin.iOS
Version: 8.10.1.64 (Indie Edition)
Hash: e6ebd18
Branch: master
Build date: 2015-05-21 21:55:09-0400

Xamarin.Mac
Not Installed

Build Information
Release ID: 509020004
Git revision: 288eb01e990f2d93b856c9600a0c40708b930128
Build date: 2015-06-01 14:29:52-04
Xamarin addins: c12ed369b0e05dc5c35c9350fdcbc00a46c0ff99

Operating System
Mac OS X 10.10.3
Darwin darrelliu-ltm.internal.salesforce.com 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 Marek Safar 2015-06-03 06:06:03 UTC
Fixed in master and 4.2 branch