2008-07-14 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / ecore.cs
index 7a798ec8d1fecfe342d89106abf0e1063ce5c96e..e8e0e6f3b86a32a5505d15ec3cdf75e2060dc7dd 100644 (file)
@@ -1336,7 +1336,7 @@ namespace Mono.CSharp {
        /// </summary>
        public abstract class TypeCast : Expression
        {
-               protected Expression child;
+               protected readonly Expression child;
 
                protected TypeCast (Expression child, Type return_type)
                {
@@ -1383,9 +1383,7 @@ namespace Mono.CSharp {
 
                protected override void CloneTo (CloneContext clonectx, Expression t)
                {
-                       TypeCast target = (TypeCast) t;
-
-                       target.child = child.Clone (clonectx);
+                       // Nothing to clone
                }
 
                public override bool IsNull {
@@ -2086,24 +2084,12 @@ namespace Mono.CSharp {
        }
        
        public class OpcodeCast : TypeCast {
-               OpCode op, op2;
-               bool second_valid;
+               readonly OpCode op;
                
                public OpcodeCast (Expression child, Type return_type, OpCode op)
                        : base (child, return_type)
-                       
-               {
-                       this.op = op;
-                       second_valid = false;
-               }
-
-               public OpcodeCast (Expression child, Type return_type, OpCode op, OpCode op2)
-                       : base (child, return_type)
-                       
                {
                        this.op = op;
-                       this.op2 = op2;
-                       second_valid = true;
                }
 
                public override Expression DoResolve (EmitContext ec)
@@ -2118,9 +2104,6 @@ namespace Mono.CSharp {
                {
                        base.Emit (ec);
                        ec.ig.Emit (op);
-
-                       if (second_valid)
-                               ec.ig.Emit (op2);
                }
 
                public Type UnderlyingType {
@@ -3449,6 +3432,10 @@ namespace Mono.CSharp {
                                
                                p = Delegate.GetInvokeMethod (null, p).ReturnType;
                                q = Delegate.GetInvokeMethod (null, q).ReturnType;
+                               if (p == TypeManager.void_type && q != TypeManager.void_type)
+                                       return 2;
+                               if (q == TypeManager.void_type && p != TypeManager.void_type)
+                                       return 1;
                        } else {
                                if (argument_type == p)
                                        return 1;
@@ -3723,6 +3710,8 @@ namespace Mono.CSharp {
                protected virtual void Error_InvalidArguments (EmitContext ec, Location loc, int idx, MethodBase method,
                                                                                                        Argument a, ParameterData expected_par, Type paramType)
                {
+                       ExtensionMethodGroupExpr emg = this as ExtensionMethodGroupExpr;
+
                        if (a is CollectionElementInitializer.ElementInitializerArgument) {
                                Report.SymbolRelatedToPreviousError (method);
                                if ((expected_par.ParameterModifier (idx) & Parameter.Modifier.ISBYREF) != 0) {
@@ -3734,8 +3723,15 @@ namespace Mono.CSharp {
                                          TypeManager.CSharpSignature (method));
                        } else if (delegate_type == null) {
                                Report.SymbolRelatedToPreviousError (method);
-                               Report.Error (1502, loc, "The best overloaded method match for `{0}' has some invalid arguments",
-                                                 TypeManager.CSharpSignature (method));
+                               if (emg != null) {
+                                       Report.Error (1928, loc,
+                                               "Type `{0}' does not contain a member `{1}' and the best extension method overload `{2}' has some invalid arguments",
+                                               emg.ExtensionExpression.GetSignatureForError (),
+                                               emg.Name, TypeManager.CSharpSignature (method));
+                               } else {
+                                       Report.Error (1502, loc, "The best overloaded method match for `{0}' has some invalid arguments",
+                                               TypeManager.CSharpSignature (method));
+                               }
                        } else
                                Report.Error (1594, loc, "Delegate `{0}' has some invalid arguments",
                                        TypeManager.CSharpName (delegate_type));
@@ -3746,10 +3742,10 @@ namespace Mono.CSharp {
                        if (((mod & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) ^
                                (a.Modifier & (Parameter.Modifier.REF | Parameter.Modifier.OUT))) != 0) {
                                if ((mod & Parameter.Modifier.ISBYREF) == 0)
-                                       Report.Error (1615, loc, "Argument `{0}' should not be passed with the `{1}' keyword",
+                                       Report.Error (1615, loc, "Argument `#{0}' does not require `{1}' modifier. Consider removing `{1}' modifier",
                                                index, Parameter.GetModifierSignature (a.Modifier));
                                else
-                                       Report.Error (1620, loc, "Argument `{0}' must be passed with the `{1}' keyword",
+                                       Report.Error (1620, loc, "Argument `#{0}' is missing `{1}' modifier",
                                                index, Parameter.GetModifierSignature (mod));
                        } else {
                                string p1 = a.GetSignatureForError ();
@@ -3760,7 +3756,14 @@ namespace Mono.CSharp {
                                        Report.SymbolRelatedToPreviousError (a.Expr.Type);
                                        Report.SymbolRelatedToPreviousError (paramType);
                                }
-                               Report.Error (1503, loc, "Argument {0}: Cannot convert type `{1}' to `{2}'", index, p1, p2);
+
+                               if (idx == 0 && emg != null) {
+                                       Report.Error (1929, loc,
+                                               "Extension method instance type `{0}' cannot be converted to `{1}'", p1, p2);
+                               } else {
+                                       Report.Error (1503, loc,
+                                               "Argument `#{0}' cannot convert `{1}' expression to type `{2}'", index, p1, p2);
+                               }
                        }
                }
 
@@ -3899,15 +3902,13 @@ namespace Mono.CSharp {
 
                                if (a_type != parameter)
                                        return 2;
-
-                               return 0;
+                       } else {
+                               if (delegate_type != null ?
+                                       !Delegate.IsTypeCovariant (argument.Expr, parameter) :
+                                       !Convert.ImplicitConversionExists (ec, argument.Expr, parameter))
+                                       return 2;
                        }
 
-                       if (delegate_type != null ?
-                               !Delegate.IsTypeCovariant (argument.Expr, parameter) :
-                               !Convert.ImplicitConversionExists (ec, argument.Expr, parameter))
-                               return 2;
-
                        if (arg_mod != param_mod)
                                return 1;
 
@@ -4169,8 +4170,12 @@ namespace Mono.CSharp {
                        }
 
                        Report.SetMessageRecorder (prev_recorder);
-                       if (msg_recorder != null && msg_recorder.PrintMessages ())
+                       if (msg_recorder != null && !msg_recorder.IsEmpty) {
+                               if (!may_fail)
+                                       msg_recorder.PrintMessages ();
+
                                return null;
+                       }
                        
                        int candidate_top = candidates.Count;
 
@@ -4622,7 +4627,7 @@ namespace Mono.CSharp {
        ///   Fully resolved expression that evaluates to a Field
        /// </summary>
        public class FieldExpr : MemberExpr, IAssignMethod, IMemoryLocation, IVariable {
-               public readonly FieldInfo FieldInfo;
+               public FieldInfo FieldInfo;
                readonly Type constructed_generic_type;
                VariableInfo variable_info;
                
@@ -5097,6 +5102,12 @@ namespace Mono.CSharp {
                        throw new NotSupportedException ();
 #endif                 
                }
+               
+               public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
+               {
+                       FieldInfo = storey.MutateField (FieldInfo);
+                       base.MutateHoistedGenericType (storey);
+               }               
        }
 
        
@@ -5773,7 +5784,7 @@ namespace Mono.CSharp {
                        get { return false; }
                }
 
-               public override ILocalVariable Variable {
+               protected override ILocalVariable Variable {
                        get { return li; }
                }