Bug 22054 - Mono C# compiler incorrectly emits CS0019 if the lhs of a null coalescing operator is a integer type that is larger than the integer type on the rhs
Summary: Mono C# compiler incorrectly emits CS0019 if the lhs of a null coalescing op...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-08-12 17:59 UTC by emoriarty
Modified: 2014-08-14 05:54 UTC (History)
2 users (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 emoriarty 2014-08-12 17:59:12 UTC
The Mono C# compiler incorrectly emits CS0019 if the lhs of a null coalescing operator is a integer type that is larger than the integer type on the rhs.

===== Test.cs =====
     1  public class A {
     2      void Foo() {
     3          byte? byteArg = 0;
     4          short? shortArg = 0;
     5          int? intArg = 0;
     6          long? longArg = 0;
     7  
     8          // Smaller Type ?? Larger Type is Ok
     9          long? a = byteArg ?? shortArg;
    10          long? b = byteArg ?? intArg;
    11          long? c = byteArg ?? longArg;
    12          long? d = shortArg ?? intArg;
    13          long? e = shortArg ?? longArg;
    14          long? f = intArg ?? longArg;
    15  
    16          // Larger Type ?? Smaller Type Fails
    17          long? g = shortArg ?? byteArg;
    18          long? h = intArg ?? byteArg;
    19          long? i = intArg ?? shortArg;
    20          long? j = longArg ?? byteArg;
    21          long? k = longArg ?? shortArg;
    22          long? l = longArg ?? intArg;
    23      }
    24  }
===== End of Test.cs =====

# From Visual Studio 2013 Command Prompt
$ csc /t:library Test.cs
Microsoft (R) Visual C# Compiler version 12.0.21005.1
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

# Mono 3.4.0.0
$ mcs /t:library Test.cs
Test.cs(17,28): error CS0019: Operator `??' cannot be applied to operands of type `short?' and `byte?'
Test.cs(18,26): error CS0019: Operator `??' cannot be applied to operands of type `int?' and `byte?'
Test.cs(19,26): error CS0019: Operator `??' cannot be applied to operands of type `int?' and `short?'
Test.cs(20,27): error CS0019: Operator `??' cannot be applied to operands of type `long?' and `byte?'
Test.cs(21,27): error CS0019: Operator `??' cannot be applied to operands of type `long?' and `short?'
Test.cs(22,27): error CS0019: Operator `??' cannot be applied to operands of type `long?' and `int?'

# Other Mono Versions
2.11.4.0: fail
3.0.0.0: fail
3.0.7.0: fail
3.1.1.0: fail
3.2.6.0: fail
3.4.0.0: fail
master/abb5e6f7e10489: fail


Edward Moriarty | Junior Engineer
Coverity | The Leader in Development Testing
Comment 1 Marek Safar 2014-08-14 05:54:13 UTC
Fixed in master