2006-09-21 Marek Sieradzki <marek.sieradzki@gmail.com>
[mono.git] / mcs / gmcs / ecore.cs
index accb7caf88f459d1b64b4036671183b7c485f054..d40ee8a8ad912394d19b7ae55059d46e94a45a5d 100644 (file)
@@ -245,7 +245,7 @@ namespace Mono.CSharp {
                        }
 
                        // Constrains don't need to be checked for overrides
-                       GenericMethod gm = ec.DeclContainer as GenericMethod;
+                       GenericMethod gm = ec.GenericDeclContainer as GenericMethod;
                        if (gm != null && (gm.ModFlags & Modifiers.OVERRIDE) != 0) {
                                te.loc = loc;
                                return te;
@@ -303,6 +303,17 @@ namespace Mono.CSharp {
 
                }
 
+               protected void Error_CannotAssign (string to, string roContext)
+               {
+                       Report.Error (1656, loc, "Cannot assign to `{0}' because it is a `{1}'",
+                               to, roContext);
+               }
+
+               public static void Error_VoidInvalidInTheContext (Location loc)
+               {
+                       Report.Error (1547, loc, "Keyword `void' cannot be used in this context");
+               }
+
                public virtual void Error_ValueCannotBeConverted (Location loc, Type target, bool expl)
                {
                        if (Type.FullName == target.FullName){
@@ -384,23 +395,22 @@ namespace Mono.CSharp {
                        if ((flags & ResolveFlags.MaskExprClass) == ResolveFlags.Type) 
                                return ResolveAsTypeStep (ec, false);
 
-                       bool old_do_flow_analysis = ec.DoFlowAnalysis;
-                       bool old_omit_struct_analysis = ec.OmitStructFlowAnalysis;
+                       bool do_flow_analysis = ec.DoFlowAnalysis;
+                       bool omit_struct_analysis = ec.OmitStructFlowAnalysis;
                        if ((flags & ResolveFlags.DisableFlowAnalysis) != 0)
-                               ec.DoFlowAnalysis = false;
+                               do_flow_analysis = false;
                        if ((flags & ResolveFlags.DisableStructFlowAnalysis) != 0)
-                               ec.OmitStructFlowAnalysis = true;
+                               omit_struct_analysis = true;
 
                        Expression e;
-                       if (this is SimpleName) {
-                               bool intermediate = (flags & ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
-                               e = ((SimpleName) this).DoResolve (ec, intermediate);
+                       using (ec.WithFlowAnalysis (do_flow_analysis, omit_struct_analysis)) {
+                               if (this is SimpleName) {
+                                       bool intermediate = (flags & ResolveFlags.Intermediate) == ResolveFlags.Intermediate;
+                                       e = ((SimpleName) this).DoResolve (ec, intermediate);
+                               } else {
+                                       e = DoResolve (ec);
+                               }
                        }
-                       else 
-                               e = DoResolve (ec);
-
-                       ec.DoFlowAnalysis = old_do_flow_analysis;
-                       ec.OmitStructFlowAnalysis = old_omit_struct_analysis;
 
                        if (e == null)
                                return null;
@@ -659,14 +669,49 @@ namespace Mono.CSharp {
                        if (mi == null)
                                return null;
 
-                       int count = mi.Length;
+                       if (mi.Length > 1) {
+                               bool is_interface = qualifier_type != null && qualifier_type.IsInterface;
+                               MemberInfo non_method = null;
+                               ArrayList methods = new ArrayList (2);
+
+                               foreach (MemberInfo m in mi) {
+                                       if (m is MethodBase) {
+                                               methods.Add (m);
+                                               continue;
+                                       }
+
+                                       if (non_method == null) {
+                                               non_method = m;
+                                               continue;
+                                       }
+
+                                       if (!is_interface)
+                                               continue;
+
+                                       Report.SymbolRelatedToPreviousError (m);
+                                       Report.SymbolRelatedToPreviousError (non_method);
+                                       Report.Error (229, loc, "Ambiguity between `{0}' and `{1}'",
+                                               TypeManager.GetFullNameSignature (m), TypeManager.GetFullNameSignature (non_method));
+                                       return null;
+                               }
+
+                               if (non_method != null && is_interface) {
+                                       MethodBase method = (MethodBase)methods[0];
+                                       Report.SymbolRelatedToPreviousError (method);
+                                       Report.SymbolRelatedToPreviousError (non_method);
+                                       Report.Warning (467, 2, loc, "Ambiguity between method `{0}' and non-method `{1}'. Using method `{0}'",
+                                               TypeManager.CSharpSignature (method), TypeManager.GetFullNameSignature (non_method));
+                               }
+
+                               if (methods.Count == 0)
+                                       return new MethodGroupExpr (mi, loc);
+
+                               return new MethodGroupExpr (methods, loc);
+                       }
 
                        if (mi [0] is MethodBase)
                                return new MethodGroupExpr (mi, loc);
 
-                       if (count > 1)
-                               return null;
-
                        return ExprClassFromMemberInfo (container_type, mi [0], loc);
                }
 
@@ -1098,7 +1143,7 @@ namespace Mono.CSharp {
                {
                        Expression target;
                        
-                       using (ec.WithCheckState (true, ec.ConstantCheckState)) {
+                       using (ec.With (EmitContext.Flags.CheckState, true)) {
                                target = Convert.ImplicitConversion (ec, source, TypeManager.int32_type, loc);
                                if (target == null)
                                        target = Convert.ImplicitConversion (ec, source, TypeManager.uint32_type, loc);
@@ -2012,7 +2057,7 @@ namespace Mono.CSharp {
 
                public override FullNamedExpression ResolveAsTypeStep (IResolveContext ec, bool silent)
                {
-                       FullNamedExpression fne = ec.DeclContainer.LookupGeneric (Name, loc);
+                       FullNamedExpression fne = ec.GenericDeclContainer.LookupGeneric (Name, loc);
                        if (fne != null)
                                return fne.ResolveAsTypeStep (ec, silent);
 
@@ -3107,12 +3152,11 @@ namespace Mono.CSharp {
                                // "a.b" is initialized, not whether the whole struct "a" is initialized.
 
                                if (lvalue_instance) {
-                                       bool old_do_flow_analysis = ec.DoFlowAnalysis;
-                                       ec.DoFlowAnalysis = false;
-                                       Expression right_side =
-                                               out_access ? EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
-                                       InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side, loc);
-                                       ec.DoFlowAnalysis = old_do_flow_analysis;
+                                       using (ec.With (EmitContext.Flags.DoFlowAnalysis, false)) {
+                                               Expression right_side =
+                                                       out_access ? EmptyExpression.LValueMemberOutAccess : EmptyExpression.LValueMemberAccess;
+                                               InstanceExpression = InstanceExpression.ResolveLValue (ec, right_side, loc);
+                                       }
                                } else {
                                        ResolveFlags rf = ResolveFlags.VariableOrValue | ResolveFlags.DisableFlowAnalysis;
                                        InstanceExpression = InstanceExpression.Resolve (ec, rf);
@@ -3374,8 +3418,10 @@ namespace Mono.CSharp {
                        else 
                                ig.Emit (OpCodes.Stfld, FieldInfo);
                        
-                       if (temp != null)
+                       if (temp != null) {
                                temp.Emit (ec);
+                               temp.Release (ec);
+                       }
                }
 
                public override void Emit (EmitContext ec)
@@ -3602,10 +3648,10 @@ namespace Mono.CSharp {
 
                        InstanceExpression.CheckMarshalByRefAccess ();
 
-                       if (must_do_cs1540_check && InstanceExpression != EmptyExpression.Null &&
-                           InstanceExpression.Type != ec.ContainerType &&
-                           ec.ContainerType.IsSubclassOf (PropertyInfo.DeclaringType) &&
-                           !InstanceExpression.Type.IsSubclassOf (ec.ContainerType)) {
+                       if (must_do_cs1540_check && (InstanceExpression != EmptyExpression.Null) &&
+                           !TypeManager.IsInstantiationOfSameGenericType (InstanceExpression.Type, ec.ContainerType) &&
+                           TypeManager.IsFamilyAccessible (ec.ContainerType, PropertyInfo.DeclaringType) &&
+                           !TypeManager.IsFamilyAccessible (InstanceExpression.Type, ec.ContainerType)) {
                                Error_CannotAccessProtected (loc, PropertyInfo, InstanceExpression.Type, ec.ContainerType);
                                return false;
                        }
@@ -3831,8 +3877,10 @@ namespace Mono.CSharp {
                        
                        Invocation.EmitCall (ec, IsBase, IsStatic, InstanceExpression, setter, args, loc, false, prepared);
                        
-                       if (temp != null)
+                       if (temp != null) {
                                temp.Emit (ec);
+                               temp.Release (ec);
+                       }
                }
        }