Nothing to see here
[mono.git] / mcs / mcs / literal.cs
index 77582d130afa3d1106ac96de87026e6a616ce81c..77a8832036946b54ccc16c86ed652b6eb23c8ee8 100644 (file)
@@ -43,6 +43,7 @@ namespace Mono.CSharp {
                
                public override Expression CreateExpressionTree (EmitContext ec)
                {
+                       // HACK: change type to be object
                        type = TypeManager.object_type;
                        return base.CreateExpressionTree (ec);
                }               
@@ -80,10 +81,14 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override Constant ConvertImplicitly (Type targetType)
+               public override Constant ConvertExplicitly (bool inCheckedContext, Type targetType)
                {
                        if (targetType.IsPointer)
-                               return new EmptyConstantCast (NullPointer.Null, targetType);
+                               return new EmptyConstantCast (new NullPointer (loc), targetType);
+
+                       // Exlude internal compiler types
+                       if (targetType == TypeManager.anonymous_method_type)
+                               return null;
 
                        if (TypeManager.IsReferenceType (targetType))
                                return new EmptyConstantCast (this, targetType);
@@ -91,6 +96,17 @@ namespace Mono.CSharp {
                        return null;
                }
 
+               public override Constant ConvertImplicitly (Type targetType)
+               {
+                       //
+                       // Null literal is of object type
+                       //
+                       if (targetType == TypeManager.object_type)
+                               return this;
+
+                       return ConvertExplicitly (false, targetType);
+               }
+
                public override object GetValue ()
                {
                        return null;
@@ -121,24 +137,14 @@ namespace Mono.CSharp {
                public override bool IsZeroInteger {
                        get { return true; }
                }
-
-               public override Constant ConvertExplicitly(bool inCheckedContext, Type target_type)
-               {
-                       if (!TypeManager.IsValueType (target_type))
-                               return new EmptyConstantCast (this, target_type);
-
-                       return null;
-               }
        }
 
        //
        // A null literal in a pointer context
        //
        public class NullPointer : NullLiteral {
-               public static readonly NullLiteral Null = new NullPointer ();
-
-               private NullPointer ():
-                       base (Location.Null)
+               public NullPointer (Location loc):
+                       base (loc)
                {
                        type = TypeManager.object_type;
                }
@@ -147,7 +153,9 @@ namespace Mono.CSharp {
                {
                        ILGenerator ig = ec.ig;
                                
-                       // TODO: why not use Ldnull instead ?
+                       //
+                       // Emits null pointer
+                       //
                        ig.Emit (OpCodes.Ldc_I4_0);
                        ig.Emit (OpCodes.Conv_U);
                }