2008-05-06 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Tue, 6 May 2008 11:23:48 +0000 (11:23 -0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 6 May 2008 11:23:48 +0000 (11:23 -0000)
* nullable.cs (NullCoalescingOperator): Result is underlying type of left,
when left is nullable type.

svn path=/trunk/mcs/; revision=102603

mcs/mcs/ChangeLog
mcs/mcs/nullable.cs

index ac98ed4ead4218d29d50841e485b3f115885205b..4f5155f4cd1c65c9987eaa5216eff8b4245e4782 100644 (file)
@@ -1,3 +1,8 @@
+2008-05-06  Marek Safar  <marek.safar@gmail.com>
+
+       * nullable.cs (NullCoalescingOperator): Result is underlying type of left,
+       when left is nullable type.
+
 2008-05-06  Marek Safar  <marek.safar@gmail.com>
 
        A fix for bug #386628
index 0f11bfe11ae7d1f8b6347154e9d6e9014082b9f5..857b3b61ae602b85a6396503d47659a61b49607d 100644 (file)
@@ -987,20 +987,20 @@ namespace Mono.CSharp.Nullable
                        Type ltype = left.Type, rtype = right.Type;
 
                        //
-                       // If left is a nullable type and an implicit conversion exists from right to left,
-                       // the result type is left
+                       // If left is a nullable type and an implicit conversion exists from right to underlying type of left,
+                       // the result is underlying type of left
                        //
                        if (TypeManager.IsNullableType (ltype) && left.eclass != ExprClass.MethodGroup) {
                                unwrap = Unwrap.Create (left, ec);
                                if (unwrap == null)
                                        return null;
 
-                               if (Convert.ImplicitConversionExists (ec, right, ltype)) {
+                               if (Convert.ImplicitConversionExists (ec, right, unwrap.Type)) {
                                        left = unwrap;
-                                       right = Convert.ImplicitConversion (ec, right, ltype, loc);
                                        type = left.Type;
+                                       right = Convert.ImplicitConversion (ec, right, type, loc);
                                        return this;
-                               }
+                               }                       
                        } else if (TypeManager.IsReferenceType (ltype) && right.eclass != ExprClass.MethodGroup) {
                                if (Convert.ImplicitConversionExists (ec, right, ltype)) {
                                        //
@@ -1025,7 +1025,7 @@ namespace Mono.CSharp.Nullable
                                return null;
                        }
 
-                       if (!Convert.ImplicitConversionExists (ec, left, rtype)) {
+                       if (!Convert.ImplicitConversionExists (ec, unwrap != null ? unwrap : left, rtype)) {
                                Binary.Error_OperatorCannotBeApplied (left, right, "??", loc);
                                return null;
                        }
@@ -1036,7 +1036,7 @@ namespace Mono.CSharp.Nullable
                        if (left.IsNull)
                                return ReducedExpression.Create (right, this).Resolve (ec);
 
-                       left = Convert.ImplicitConversion (ec, left, rtype, loc);
+                       left = Convert.ImplicitConversion (ec, unwrap != null ? unwrap : left, rtype, loc);
                        type = rtype;
                        return this;
                }