[mcs] nonliteral constants pattern matching
[mono.git] / mcs / mcs / nullable.cs
index 853ec92bb0f59c5b258abcb0e23a8843bcb893ec..e857e365410152f1613f0675e5fc83ffae1f8b30 100644 (file)
@@ -33,7 +33,7 @@ namespace Mono.CSharp.Nullable
                        this.loc = loc;
                }
 
-               public override TypeSpec ResolveAsType (IMemberContext ec)
+               public override TypeSpec ResolveAsType (IMemberContext ec, bool allowUnboundTypeArguments = false)
                {
                        eclass = ExprClass.Type;
 
@@ -435,6 +435,12 @@ namespace Mono.CSharp.Nullable
                {
                }
 
+               public override bool IsNull {
+                       get {
+                               return expr.IsNull;
+                       }
+               }
+
                public override bool ContainsEmitWithAwait ()
                {
                        return unwrap.ContainsEmitWithAwait ();
@@ -1135,24 +1141,35 @@ namespace Mono.CSharp.Nullable
                                if (right.IsNull)
                                        return ReducedExpression.Create (left, this);
 
-                               if (Convert.ImplicitConversionExists (ec, right, unwrap.Type)) {
-                                       left = unwrap;
-                                       ltype = left.Type;
+                               Expression conv;
+                               if (right.Type.IsNullableType) {
+                                       conv = right.Type == ltype ? right : Convert.ImplicitNulableConversion (ec, right, ltype);
+                                       if (conv != null) {
+                                               right = conv;
+                                               type = ltype;
+                                               return this;
+                                       }
+                               } else {
+                                       conv = Convert.ImplicitConversion (ec, right, unwrap.Type, loc);
+                                       if (conv != null) {
+                                               left = unwrap;
+                                               ltype = left.Type;
 
-                                       //
-                                       // If right is a dynamic expression, the result type is dynamic
-                                       //
-                                       if (right.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
-                                               type = right.Type;
+                                               //
+                                               // If right is a dynamic expression, the result type is dynamic
+                                               //
+                                               if (right.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
+                                                       type = right.Type;
 
-                                               // Need to box underlying value type
-                                               left = Convert.ImplicitBoxingConversion (left, ltype, type);
+                                                       // Need to box underlying value type
+                                                       left = Convert.ImplicitBoxingConversion (left, ltype, type);
+                                                       return this;
+                                               }
+
+                                               right = conv;
+                                               type = ltype;
                                                return this;
                                        }
-
-                                       right = Convert.ImplicitConversion (ec, right, ltype, loc);
-                                       type = ltype;
-                                       return this;
                                }
                        } else if (TypeSpec.IsReferenceType (ltype)) {
                                if (Convert.ImplicitConversionExists (ec, right, ltype)) {