Bug 37080 - Compiler not evaluating elvis operator ?. correctly
Summary: Compiler not evaluating elvis operator ?. correctly
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 4.0.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-12-16 14:06 UTC by Kerry
Modified: 2015-12-23 08:12 UTC (History)
5 users (show)

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


Attachments
Test project to be opened in Xamarin Studio (11.98 KB, application/zip)
2015-12-16 14:06 UTC, Kerry
Details

Description Kerry 2015-12-16 14:06:52 UTC
Created attachment 14315 [details]
Test project to be opened in Xamarin Studio

I've noticed what appears to be a compiler bug. The following code uses Newtonsoft.Json to parse JSON.

var deserialized = JObject.Parse("{ \"a\": \"b\", \"c\": \"d\", \"e\": \"f\" }");

var oldTest = new
    {
        A = deserialized["a"] != null ? deserialized["a"].Value<string>() : null,
        B = deserialized["b"] != null ? deserialized["b"].Value<string>() : null,
        C = deserialized["c"] != null ? deserialized["c"].Value<string>() : null,
        D = deserialized["d"] != null ? deserialized["d"].Value<string>() : null,
        E = deserialized["e"] != null ? deserialized["e"].Value<string>() : null,
        F = deserialized["f"] != null ? deserialized["f"].Value<string>() : null
    };

var newTest = new
    {
        A = deserialized["a"]?.Value<string>(),
        B = deserialized["b"]?.Value<string>(),
        C = deserialized["c"]?.Value<string>(),
        D = deserialized["d"]?.Value<string>(),
        E = deserialized["e"]?.Value<string>(),
        F = deserialized["f"]?.Value<string>()
    };

The above code throws a ArgumentNullException in the call to Value<string>() while assigning newTest.B. The expected behavior would be to assign null to newTest.B. This problem happens only when compiling on the Mac. The problem does not occur when using Visual Studio connected to a Mac.
Comment 1 Sebastien Pouliot 2015-12-16 14:10:16 UTC
Xamarin.iOS does not ship a C# compiler. This comes with the version of Mono that is installed on your system.

To help the mono team please provide all* versions information about your software.

* The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 2 Kerry 2015-12-16 14:17:38 UTC
=== Xamarin Studio ===

Version 5.10.1 (build 6)
Installation UUID: e5d1d8bc-748e-473a-9f9a-12679e242bbe
Runtime:
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

=== Xamarin.Profiler ===

Not Installed

=== Xamarin.Android ===

Version: 6.0.0.34 (Enterprise Edition)
Android SDK: /Users/kwl/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)
		5.0   (API level 21)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.0

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 ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin Inspector ===

Version: 0.3.2.3
Hash: 1b526e6
Branch: master
Build date: Tue Nov 17 20:54:30 UTC 2015

=== Apple Developer Tools ===

Xcode 7.2 (9548)
Build 7C68

=== Xamarin.iOS ===

Version: 9.4.0.0 (Enterprise Edition)
Hash: 7322991
Branch: master
Build date: 2015-12-08 16:20:29-0500

=== Xamarin.Mac ===

Version: 2.4.0.109 (Enterprise Edition)

=== Build Information ===

Release ID: 510010006
Git revision: 0b60eecdb531933734519c13257d16a780274aab
Build date: 2015-12-04 20:28:20-05
Xamarin addins: 9876fd7c9837977178411ec7375b4352c0a0d6af
Build lane: monodevelop-lion-cycle6-baseline

=== Operating System ===

Mac OS X 10.10.5
Darwin kerrys-macbook-pro.fritz.box 14.5.0 Darwin Kernel Version 14.5.0
    Tue Sep  1 21:23:09 PDT 2015
    root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
Comment 3 Marek Safar 2015-12-18 15:42:11 UTC
I can repro the issue
Comment 4 Marek Safar 2015-12-18 20:15:10 UTC
Fixed in master
Comment 5 Kerry 2015-12-23 08:12:02 UTC
Thanks! Any idea why this only surfaced on OS X?

Note You need to log in before you can comment on or make changes to this bug.