Bug 32054

Summary: Internal compiler error using Null Coalescing Operator on System.Nullable
Product: [Mono] Compilers Reporter: João Vitor <jvlppm>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: jahmai, mono-bugs+mono
Priority: ---    
Version: 4.0.0   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description João Vitor 2015-07-16 19:20:25 UTC
Code:

    class Test
    {
        int? _state;
        public bool Working() => _state?.ToString() != "";
    }


Error:
Test.cs(34,34): Error CS0584: Internal compiler error: /Users/joao/Projects/test/TestNullable/Test.cs(9,34): Mono.CSharp.Nullable.Unwrap ExprClass is Invalid after resolve (CS0584) (TestNullable)


=== Xamarin Studio ===

Version 5.9.4 (build 5)
Installation UUID: 0dca64e4-d900-4836-b697-c381adbe2408
Runtime:
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Xamarin.Android ===

Version: 5.1.4.16 (Indie Edition)
Android SDK: /Users/joao/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Apple Developer Tools ===

Xcode 6.4 (7720)
Build 6E35b

=== Xamarin.Mac ===

Not Installed

=== Xamarin.iOS ===

Version: 8.10.3.2 (Indie Edition)
Hash: 8b265d6
Branch: master
Build date: 2015-06-30 15:19:13-0400

=== Build Information ===

Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.4
Darwin Joaos-MacBook-Pro.local 14.4.0 Darwin Kernel Version 14.4.0
    Thu May 28 11:35:04 PDT 2015
    root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64
Comment 1 Marek Safar 2015-07-20 12:44:02 UTC
Fixed in master and Mono 4.2
Comment 2 João Vitor 2015-08-23 12:22:12 UTC
On another instance the code does compile, but I receive "Invalid IL code" when trying to run the method that uses ?. on Nullable.

I'm assuming this is the same bug, and it was fixed as well.

Method that generates invalid IL code:

        public static Vector2 GetSpeedMultiplier(this Terrain terrain)
        {
            return terrain?.Properties.Get("speed_multiplier")?.AsVector2() ?? Vector2.One;
        }

Equivalent method that does work:

        public static Vector2 GetSpeedMultiplier(this Terrain terrain)
        {
            if (terrain == null)
                return Vector2.One;
            var multiplier = terrain.Properties.Get("speed_multiplier");
            if (multiplier == null)
                return Vector2.One;
            var vector = multiplier.Value.AsVector2();
            if (vector == null)
                return Vector2.One;
            
            return vector.Value;
        }

Terrain in a class,
both Property and Vector2 are structs.

Should I report another bug?

System.InvalidProgramException: Invalid IL code in Core.Model.GamePlay.Extensions:GetSpeedMultiplier (FuncWorks.XNA.XTiled.Terrain): IL_0044: call      0x06000078


  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr3/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.3/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (object) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr3/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.3/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1006
  at at MonoMac.AppKit.AppKitSynchronizationContext/<Post>c__AnonStorey0.<>m__0 () <IL 0x0000c, 0x00032>
  at at MonoMac.Foundation.NSAsyncActionDispatcher.Apply () <IL 0x00008, 0x0003c>
  at at (wrapper dynamic-method) object.[MonoMac.Foundation.NSAsyncActionDispatcher.Void Apply()] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector) <IL 0x0000b, 0x0004f>
  at at (wrapper native-to-managed) object.[MonoMac.Foundation.NSAsyncActionDispatcher.Void Apply()] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector) <IL 0x00057, 0x0012b>
  at at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0x00012>
  at at MonoMac.AppKit.NSApplication.Main (string[]) <IL 0x00041, 0x00107>
  at Mac.Blue.Program.Main (string[]) [0x0001d] in /Users/joao/Projects/jvlppm/game-test/Targets/Mac/Blue/Main.cs:24


=== Xamarin Studio ===

Version 5.9.5 (build 10)
Installation UUID: 0dca64e4-d900-4836-b697-c381adbe2408
Runtime:
	Mono 4.0.3 ((detached/d6946b4)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400030020

=== Apple Developer Tools ===

Xcode 6.4 (7720)
Build 6E35b

=== Xamarin.iOS ===

Version: 8.10.4.46 (Indie Edition)
Hash: 2c66d2f
Branch: master
Build date: 2015-08-04 13:52:25-0400

=== Xamarin.Android ===

Version: 5.1.5.3 (Indie Edition)
Android SDK: /Users/joao/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Not Installed

=== Xamarin.Mac ===

Not Installed

=== Build Information ===

Release ID: 509050010
Git revision: 48d16bc4f12ce3938964fc7c3d72fdc6887ad4ad
Build date: 2015-08-18 16:55:24-04
Xamarin addins: c2d51b360ad9f59e689046d47030df27de28f94a

=== Operating System ===

Mac OS X 10.10.4
Darwin Joaos-MacBook-Pro.local 14.4.0 Darwin Kernel Version 14.4.0
    Thu May 28 11:35:04 PDT 2015
    root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64
Comment 3 Jahmai 2015-08-26 02:01:49 UTC
Another C#6 issue that should be back patched to 4.0.

This is a straight up lie:

https://developer.xamarin.com/guides/cross-platform/advanced/csharp_six/

"This document introduces the new features of C# 6.0. C# 6 is fully supported by the mono compiler and developers can start using the new features across all the Xamarin target platforms."

"The Mono C# 6 compiler is included in Mono 4.0 and later, which is freely available for download. Xamarin Studio automatically updates the Mono installation on your system."

Yet there are 2 breaking issues with auto properties and also this issue.

All these issues should be hotfixed to 4.0, or 4.2 should be put into the stable branch as early as possible.