Bug 19938 - Enum?/Enum comparision in Expressions generate wrong initialisation bytecodes
Summary: Enum?/Enum comparision in Expressions generate wrong initialisation bytecodes
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-05-20 13:02 UTC by David Schmitt
Modified: 2014-05-27 10:15 UTC (History)
1 user (show)

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


Attachments
mono 3.2.8 compiled exe (4.50 KB, application/octet-stream)
2014-05-20 13:02 UTC, David Schmitt
Details
complete source (565 bytes, text/plain)
2014-05-20 13:02 UTC, David Schmitt
Details
.net compiled exe (6.00 KB, application/octet-stream)
2014-05-20 13:03 UTC, David Schmitt
Details


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 David Schmitt 2014-05-20 13:02:04 UTC
Created attachment 6848 [details]
mono 3.2.8 compiled exe

Example code:

    qry.Count(t => t.Property == TestEnum.A)

where "t.Property" is of type "TestEnum?".

Expected result: the result is the number of "t"s where t.Property equals TestEnum.A

Actual result:

Unhandled Exception:
System.InvalidOperationException: The binary operator Equal is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'.
  at System.Linq.Expressions.Expression.GetEqualityComparisonOperator (ExpressionType binaryType, System.String opName, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, Boolean liftToNull) [0x00000] in <filename unknown>:0
  at System.Linq.Expressions.Expression.Equal (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, Boolean liftToNull, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0
  at System.Linq.Expressions.Expression.Equal (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right) [0x00000] in <filename unknown>:0
  at ConsoleApplication2.Program.TestQry (IQueryable`1 qry) [0x00000] in <filename unknown>:0
  at ConsoleApplication2.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: The binary operator Equal is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'.
  at System.Linq.Expressions.Expression.GetEqualityComparisonOperator (ExpressionType binaryType, System.String opName, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, Boolean liftToNull) [0x00000] in <filename unknown>:0
  at System.Linq.Expressions.Expression.Equal (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, Boolean liftToNull, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0
  at System.Linq.Expressions.Expression.Equal (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right) [0x00000] in <filename unknown>:0
  at ConsoleApplication2.Program.TestQry (IQueryable`1 qry) [0x00000] in <filename unknown>:0
  at ConsoleApplication2.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0


Analysis

reverse engineering the function with ILSpy shows mono converting this to "qry.Count((Test t) => (int?)t.Property == 0);" while CSC.EXE compiles this as "qry.Count((Test t) => (int?)t.Property == (int?)0);"


Please find attached the complete source and the mono compiled exe and the .net compiled exe.

I'm running 

Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4~dasz1)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen
Comment 1 David Schmitt 2014-05-20 13:02:26 UTC
Created attachment 6849 [details]
complete source
Comment 2 David Schmitt 2014-05-20 13:03:07 UTC
Created attachment 6850 [details]
.net compiled exe
Comment 3 Marek Safar 2014-05-27 10:15:27 UTC
Fixed in master