**** Merged from MCS ****
authorMartin Baulig <martin@novell.com>
Mon, 18 Oct 2004 17:55:47 +0000 (17:55 -0000)
committerMartin Baulig <martin@novell.com>
Mon, 18 Oct 2004 17:55:47 +0000 (17:55 -0000)
svn path=/trunk/mcs/; revision=35089

mcs/gmcs/ChangeLog
mcs/gmcs/attribute.cs
mcs/gmcs/const.cs
mcs/gmcs/decl.cs
mcs/gmcs/ecore.cs
mcs/gmcs/expression.cs
mcs/gmcs/generic.cs
mcs/gmcs/namespace.cs

index 696a5c5ff5105ffdee0fa2bb609cf57754183fdc..d30fdc5ce451468f03de6d0f19aa0c0437c4df8c 100755 (executable)
@@ -1,3 +1,33 @@
+2004-10-01  Raja R Harinath  <rharinath@novell.com>
+
+       Fix #65833, test-300.cs, cs0122-5.cs, cs0122-6.cs.
+       * class.c (TypeContainer.DefineType): Flag error if
+       base types aren't accessible due to access permissions.
+       * decl.cs (DeclSpace.ResolveType): Move logic to
+       Expression.ResolveAsTypeTerminal.
+       (DeclSpace.ResolveTypeExpr): Thin layer over
+       Expression.ResolveAsTypeTerminal.
+       (DeclSpace.CheckAccessLevel, DeclSpace.FamilyAccess):
+       Refactor code into NestedAccess.  Use it.
+       (DeclSpace.NestedAccess): New.
+       * ecore.cs (Expression.ResolveAsTypeTerminal): Add new
+       argument to silence errors.  Check access permissions.
+       (TypeExpr.DoResolve, TypeExpr.ResolveType): Update.
+       * expression.cs (ProbeExpr.DoResolve): Use ResolveAsTypeTerminal.
+       (Cast.DoResolve): Likewise.
+       (New.DoResolve): Likewise.
+       (InvocationOrCast.DoResolve,ResolveStatement): Likewise.
+       (TypeOf.DoResolve): Likewise.
+
+       * expression.cs (Invocation.BetterConversion): Return the Type of
+       the better conversion.  Implement section 14.4.2.3 more faithfully.
+       (Invocation.BetterFunction): Make boolean.  Make correspondence to
+       section 14.4.2.2 explicit.
+       (Invocation.OverloadResolve): Update.
+       (Invocation): Remove is_base field.
+       (Invocation.DoResolve): Don't use is_base.  Use mg.IsBase.
+       (Invocation.Emit): Likewise.
+
 2004-09-24  Marek Safar  <marek.safar@seznam.cz>
 
        * cs-parser.jay: Reverted 642 warning fix.
index 9fed07eef878b0f39c072f7db256e4b3b3cb9f42..ab79ee95bd83ebf8c4203d7b62d9da513a7d4172 100644 (file)
@@ -211,7 +211,11 @@ namespace Mono.CSharp {
                public static bool GetAttributeArgumentExpression (Expression e, Location loc, Type arg_type, out object result)
                {
                        if (e is EnumConstant) {
-                               result = e;
+                               if (RootContext.StdLib)
+                                       result = ((EnumConstant)e).GetValueAsEnumType ();
+                               else
+                                       result = ((EnumConstant)e).GetValue ();
+
                                return true;
                        }
 
@@ -303,7 +307,6 @@ namespace Mono.CSharp {
                        }
 
                        pos_values = new object [pos_arg_count];
-                       object[] real_pos_values = new object [pos_arg_count];
 
                        //
                        // First process positional arguments 
@@ -323,21 +326,14 @@ namespace Mono.CSharp {
                                if (!GetAttributeArgumentExpression (e, Location, a.Type, out val))
                                        return null;
                                
-                               if (val is EnumConstant) {
-                                       EnumConstant econst = (EnumConstant) e;
-
-                                       pos_values [i] = val = econst.GetValue ();
-                                       real_pos_values [i] = econst.GetValueAsEnumType ();
-                               } else {
-                                       real_pos_values [i] = pos_values [i] = val;
-                               }
+                               pos_values [i] = val;
 
                                if (DoCompares){
-                                       if (usage_attr)
-                                               usage_attribute = new AttributeUsageAttribute ((AttributeTargets) val);
-                                       else if (MethodImplAttr)
+                                       if (usage_attr) {
+                                               usage_attribute = new AttributeUsageAttribute ((AttributeTargets)val);
+                                       } else if (MethodImplAttr) {
                                                this.ImplOptions = (MethodImplOptions) val;
-                                       else if (GuidAttr){
+                                       else if (GuidAttr){
                                                //
                                                // we will later check the validity of the type
                                                //
@@ -498,16 +494,16 @@ namespace Mono.CSharp {
                                        continue;
                                
                                if (j == group_in_params_array){
-                                       object v = real_pos_values [j];
+                                       object v = pos_values [j];
                                        int count = pos_arg_count - j;
 
                                        object [] array = new object [count];
-                                       real_pos_values [j] = array;
+                                       pos_values [j] = array;
                                        array [0] = v;
                                } else {
-                                       object [] array = (object []) real_pos_values [group_in_params_array];
+                                       object [] array = (object []) pos_values [group_in_params_array];
 
-                                       array [j - group_in_params_array] = real_pos_values [j];
+                                       array [j - group_in_params_array] = pos_values [j];
                                }
                        }
 
@@ -519,8 +515,8 @@ namespace Mono.CSharp {
                                object [] new_pos_values = new object [argc];
 
                                for (int p = 0; p < argc; p++)
-                                       new_pos_values [p] = real_pos_values [p];
-                               real_pos_values = new_pos_values;
+                                       new_pos_values [p] = pos_values [p];
+                               pos_values = new_pos_values;
                        }
 
                        try {
@@ -537,13 +533,13 @@ namespace Mono.CSharp {
                                        prop_infos.CopyTo   (prop_info_arr, 0);
 
                                        cb = new CustomAttributeBuilder (
-                                               (ConstructorInfo) constructor, real_pos_values,
+                                               (ConstructorInfo) constructor, pos_values,
                                                prop_info_arr, prop_values_arr,
                                                field_info_arr, field_values_arr);
                                }
                                else
                                        cb = new CustomAttributeBuilder (
-                                               (ConstructorInfo) constructor, real_pos_values);
+                                               (ConstructorInfo) constructor, pos_values);
                        } catch (NullReferenceException) {
                                // 
                                // Don't know what to do here
index f3fece7deba6cec9581d4c08c1f2cfc5a246ee52..1e0b00b2f44f83f886b5cc44c98920c570d88faa 100755 (executable)
@@ -82,8 +82,7 @@ namespace Mono.CSharp {
                        while (ttype.IsArray)
                            ttype = TypeManager.GetElementType (ttype);
                        
-                       if (!TypeManager.IsBuiltinType (ttype) &&
-                           (!ttype.IsSubclassOf (TypeManager.enum_type))) {
+                       if (!TypeManager.IsBuiltinType (ttype) && (!ttype.IsSubclassOf (TypeManager.enum_type)) && !(Expr is NullLiteral)) {
                                Report.Error (
                                        -3, Location,
                                        "Constant type is not valid (only system types are allowed)");
index 6a2dec0d2a54cdc1c75bcf3069f67ee26956472b..137ceec0f0f6aa61cd4a62848e1b99734f42f187 100755 (executable)
@@ -732,7 +732,7 @@ namespace Mono.CSharp {
 
                        int errors = Report.Errors;
 
-                       TypeExpr d = e.ResolveAsTypeTerminal (type_resolve_ec);
+                       TypeExpr d = e.ResolveAsTypeTerminal (type_resolve_ec, silent);
 
                        if ((d != null) && (d.eclass == ExprClass.Type))
                                return d;
@@ -742,7 +742,7 @@ namespace Mono.CSharp {
 
                        if (e is SimpleName){
                                SimpleName s = new SimpleName (((SimpleName) e).Name, loc);
-                               d = s.ResolveAsTypeTerminal (type_resolve_ec);
+                               d = s.ResolveAsTypeTerminal (type_resolve_ec, silent);
 
                                if ((d == null) || (d.Type == null)) {
                                        Report.Error (246, loc, "Cannot find type `{0}'", e);
@@ -803,51 +803,36 @@ namespace Mono.CSharp {
 
                        case TypeAttributes.NotPublic:
 
-                               // In same cases is null.
-                               if (TypeBuilder == null)
-                                       return true;
+                               if (TypeBuilder == null)
+                                       // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
+                                       //        However, this is invoked again later -- so safe to return true.
+                                       //        May also be null when resolving top-level attributes.
+                                       return true;
 
-                               //
-                               // This test should probably use the declaringtype.
-                               //
+                               //
+                               // This test should probably use the declaringtype.
+                               //
                                return check_type.Assembly == TypeBuilder.Assembly;
 
                        case TypeAttributes.NestedPublic:
                                return true;
 
                        case TypeAttributes.NestedPrivate:
-                               string check_type_name = check_type.FullName;
-                               string type_name = tb.FullName;
-
-                               int cio = check_type_name.LastIndexOf ('+');
-                               string container = check_type_name.Substring (0, cio);
-
-                               //
-                               // Check if the check_type is a nested class of the current type
-                               //
-                               if (check_type_name.StartsWith (type_name + "+")){
-                                       return true;
-                               }
-                               
-                               if (type_name.StartsWith (container)){
-                                       return true;
-                               }
-
-                               return false;
+                               return NestedAccessible (check_type);
 
                        case TypeAttributes.NestedFamily:
                                //
                                // Only accessible to methods in current type or any subtypes
                                //
-                               return FamilyAccessible (tb, check_type);
+                               return FamilyAccessible (check_type);
 
                        case TypeAttributes.NestedFamANDAssem:
                                return (check_type.Assembly == tb.Assembly) &&
-                                       FamilyAccessible (tb, check_type);
+                                       FamilyAccessible (check_type);
 
                        case TypeAttributes.NestedFamORAssem:
                                return (check_type.Assembly == tb.Assembly) ||
-                                       FamilyAccessible (tb, check_type);
+                                       FamilyAccessible (check_type);
 
                        case TypeAttributes.NestedAssembly:
                                return check_type.Assembly == tb.Assembly;
@@ -858,24 +843,32 @@ namespace Mono.CSharp {
 
                }
 
-               protected bool FamilyAccessible (TypeBuilder tb, Type check_type)
+               protected bool NestedAccessible (Type check_type)
                {
-                       Type declaring = check_type.DeclaringType;
-                       if (tb.IsSubclassOf (declaring))
-                               return true;
-
                        string check_type_name = check_type.FullName;
                        
+                       // At this point, we already know check_type is a nested class.
                        int cio = check_type_name.LastIndexOf ('+');
-                       string container = check_type_name.Substring (0, cio);
                        
-                       //
-                       // Check if the check_type is a nested class of the current type
-                       //
-                       if (check_type_name.StartsWith (container + "+"))
+                       // Ensure that the string 'container' has a '+' in it to avoid false matches
+                       string container = check_type_name.Substring (0, cio + 1);
+
+                       // Ensure that type_name ends with a '+' so that it can match 'container', if necessary
+                       string type_name = TypeBuilder.FullName + "+";
+
+                       // If the current class is nested inside the container of check_type,
+                       // we can access check_type even if it is private or protected.
+                       return type_name.StartsWith (container);
+               }
+
+               protected bool FamilyAccessible (Type check_type)
+               {
+                       Type declaring = check_type.DeclaringType;
+                       if (TypeBuilder == declaring ||
+                           TypeBuilder.IsSubclassOf (declaring))
                                return true;
 
-                       return false;
+                       return NestedAccessible (check_type);
                }
 
                // Access level of a type.
index 6d116bde831c0ab539cd7480b104f2a879861076..f134c340d38f8a0f0257fb94665a4fc075dc59c5 100755 (executable)
@@ -272,9 +272,24 @@ namespace Mono.CSharp {
                // value will be returned if the expression is not a type
                // reference
                //
-               public TypeExpr ResolveAsTypeTerminal (EmitContext ec)
+               public TypeExpr ResolveAsTypeTerminal (EmitContext ec, bool silent)
                {
-                       return ResolveAsTypeStep (ec) as TypeExpr;
+                       int errors = Report.Errors;
+
+                       TypeExpr te = ResolveAsTypeStep (ec) as TypeExpr;
+
+                       if (te == null || te.eclass != ExprClass.Type) {
+                               if (!silent && errors == Report.Errors)
+                                       Report.Error (246, Location, "Cannot find type '{0}'", ToString ());
+                               return null;
+                       }
+
+                       if (!te.CheckAccessLevel (ec.DeclSpace)) {
+                               Report.Error (122, Location, "'{0}' is inaccessible due to its protection level", te.Name);
+                               return null;
+                       }
+
+                       return te;
                }
               
                /// <summary>
@@ -2060,7 +2075,7 @@ namespace Mono.CSharp {
 
                        TypeParameterExpr generic_type = ds.LookupGeneric (Name, loc);
                        if (generic_type != null)
-                               return generic_type.ResolveAsTypeTerminal (ec);
+                               return generic_type.ResolveAsTypeTerminal (ec, false);
 
                        if (ec.ResolvingTypeTree){
                                int errors = Report.Errors;
@@ -2322,7 +2337,7 @@ namespace Mono.CSharp {
 
                override public Expression DoResolve (EmitContext ec)
                {
-                       return ResolveAsTypeTerminal (ec);
+                       return ResolveAsTypeTerminal (ec, true);
                }
 
                override public void Emit (EmitContext ec)
@@ -2379,7 +2394,7 @@ namespace Mono.CSharp {
 
                public virtual Type ResolveType (EmitContext ec)
                {
-                       TypeExpr t = ResolveAsTypeTerminal (ec);
+                       TypeExpr t = ResolveAsTypeTerminal (ec, false);
                        if (t == null)
                                return null;
 
@@ -2532,7 +2547,7 @@ namespace Mono.CSharp {
                                }
 
                                ConstructedType ctype = new ConstructedType (type, args, loc);
-                               return ctype.ResolveAsTypeTerminal (ec);
+                               return ctype.ResolveAsTypeTerminal (ec, false);
                        } else if (num_args > 0) {
                                Report.Error (305, loc,
                                              "Using the generic type `{0}' " +
@@ -2546,7 +2561,7 @@ namespace Mono.CSharp {
 
                public override Type ResolveType (EmitContext ec)
                {
-                       TypeExpr t = ResolveAsTypeTerminal (ec);
+                       TypeExpr t = ResolveAsTypeTerminal (ec, false);
                        if (t == null)
                                return null;
 
index e0122a85438ae354bec70621cfa20a520b64181c..c1a3b2b0c725cd0a47e21a3585c6de7adc8cf0fb 100755 (executable)
@@ -1012,7 +1012,7 @@ namespace Mono.CSharp {
        ///   size. 
        /// </remarks>
        public abstract class Probe : Expression {
-               public readonly Expression ProbeType;
+               public Expression ProbeType;
                protected Expression expr;
                protected Type probe_type;
                
@@ -1031,10 +1031,10 @@ namespace Mono.CSharp {
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       probe_type = ec.DeclSpace.ResolveType (ProbeType, false, loc);
-
-                       if (probe_type == null)
+                       ProbeType = ProbeType.ResolveAsTypeTerminal (ec, false);
+                       if (ProbeType == null)
                                return null;
+                       probe_type = ProbeType.Type;
 
                        CheckObsoleteAttribute (probe_type);
 
@@ -1768,11 +1768,12 @@ namespace Mono.CSharp {
                        if (expr == null)
                                return null;
 
-                       type = ec.DeclSpace.ResolveType (target_type, false, Location);
-                       
-                       if (type == null)
+                       TypeExpr target = target_type.ResolveAsTypeTerminal (ec, false);
+                       if (target == null)
                                return null;
 
+                       type = target.Type;
+
                        CheckObsoleteAttribute (type);
 
                        if (type.IsAbstract && type.IsSealed) {
@@ -4122,7 +4123,6 @@ namespace Mono.CSharp {
 
                Expression expr;
                MethodBase method = null;
-               bool is_base;
                
                static Hashtable method_parameter_cache;
 
@@ -4179,10 +4179,11 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Determines "better conversion" as specified in 7.4.2.3
                ///
-                ///    Returns : 1 if a->p is better
-               ///              0 if a->q or neither is better 
+               ///    Returns : p    if a->p is better,
+               ///              q    if a->q is better,
+               ///              null if neither is better
                /// </summary>
-               static int BetterConversion (EmitContext ec, Argument a, Type p, Type q, Location loc)
+               static Type BetterConversion (EmitContext ec, Argument a, Type p, Type q, Location loc)
                {
                        Type argument_type = TypeManager.TypeToCoreType (a.Type);
                        Expression argument_expr = a.Expr;
@@ -4197,71 +4198,84 @@ namespace Mono.CSharp {
                        if (p == null || q == null)
                                throw new InternalErrorException ("BetterConversion Got a null conversion");
 
-                       //
-                       // This is a special case since csc behaves this way.
-                       //
-                       if (argument_expr is NullLiteral &&
-                            p == TypeManager.string_type &&
-                            q == TypeManager.object_type)
-                               return 1;
-                       else if (argument_expr is NullLiteral &&
-                                 p == TypeManager.object_type &&
-                                 q == TypeManager.string_type)
-                               return 0;
-                       
-                        //
-                        // csc behaves this way so we emulate it. Basically, if the argument
-                        // is null and one of the types to compare is 'object' and the other
-                        // is a reference type, we prefer the other.
-                        //
-                        // I can't find this anywhere in the spec but we can interpret this
-                        // to mean that null can be of any type you wish in such a context
-                        //
-                                if (argument_expr is NullLiteral &&
-                                    !p.IsValueType &&
-                                    q == TypeManager.object_type)
-                                        return 1;
-                                else if (argument_expr is NullLiteral &&
-                                         !q.IsValueType &&
-                                         p == TypeManager.object_type)
-                                        return 0;
-
-                                
                        if (p == q)
-                               return 0;
-                       
+                               return null;
+
+                       if (argument_expr is NullLiteral) {
+                               //
+                               // If the argument is null and one of the types to compare is 'object' and
+                               // the other is a reference type, we prefer the other.
+                               //
+                               // This follows from the usual rules:
+                               //   * There is an implicit conversion from 'null' to type 'object'
+                               //   * There is an implicit conversion from 'null' to any reference type
+                               //   * There is an implicit conversion from any reference type to type 'object'
+                               //   * There is no implicit conversion from type 'object' to other reference types
+                               //  => Conversion of 'null' to a reference type is better than conversion to 'object'
+                               //
+                               //  FIXME: This probably isn't necessary, since the type of a NullLiteral is 'System.Null'.
+                               //         I think it used to be 'object' and thus needed a special case to avoid the
+                               //         immediately following two checks.
+                               //
+                               if (!p.IsValueType && q == TypeManager.object_type)
+                                       return p;
+                               if (!q.IsValueType && p == TypeManager.object_type)
+                                       return q;
+                       }
+
                        if (argument_type == p)
-                               return 1;
+                               return p;
 
                        if (argument_type == q)
-                               return 0;
+                               return q;
 
                        Expression p_tmp = new EmptyExpression (p);
                        Expression q_tmp = new EmptyExpression (q);
-                       
-                       if (Convert.ImplicitConversionExists (ec, p_tmp, q) == true &&
-                           Convert.ImplicitConversionExists (ec, q_tmp, p) == false)
-                               return 1;
+
+                       bool p_to_q = Convert.ImplicitConversionExists (ec, p_tmp, q);
+                       bool q_to_p = Convert.ImplicitConversionExists (ec, q_tmp, p);
+
+                       if (p_to_q && !q_to_p)
+                               return p;
+
+                       if (q_to_p && !p_to_q)
+                               return q;
 
                        if (p == TypeManager.sbyte_type)
                                if (q == TypeManager.byte_type || q == TypeManager.ushort_type ||
                                    q == TypeManager.uint32_type || q == TypeManager.uint64_type)
-                                       return 1;
+                                       return p;
+                       if (q == TypeManager.sbyte_type)
+                               if (p == TypeManager.byte_type || p == TypeManager.ushort_type ||
+                                   p == TypeManager.uint32_type || p == TypeManager.uint64_type)
+                                       return q;
 
                        if (p == TypeManager.short_type)
                                if (q == TypeManager.ushort_type || q == TypeManager.uint32_type ||
                                    q == TypeManager.uint64_type)
-                                       return 1;
+                                       return p;
+
+                       if (q == TypeManager.short_type)
+                               if (p == TypeManager.ushort_type || p == TypeManager.uint32_type ||
+                                   p == TypeManager.uint64_type)
+                                       return q;
 
                        if (p == TypeManager.int32_type)
                                if (q == TypeManager.uint32_type || q == TypeManager.uint64_type)
-                                       return 1;
+                                       return p;
+
+                       if (q == TypeManager.int32_type)
+                               if (p == TypeManager.uint32_type || p == TypeManager.uint64_type)
+                                       return q;
 
                        if (p == TypeManager.int64_type)
                                if (q == TypeManager.uint64_type)
-                                       return 1;
+                                       return p;
+                       if (q == TypeManager.int64_type)
+                               if (p == TypeManager.uint64_type)
+                                       return q;
 
-                       return 0;
+                       return null;
                }
                
                /// <summary>
@@ -4270,12 +4284,12 @@ namespace Mono.CSharp {
                /// </summary>
                /// <remarks>
                ///    Returns an integer indicating :
-               ///     0 if candidate ain't better
-               ///     1 if candidate is better than the current best match
+               ///     false if candidate ain't better
+               ///     true if candidate is better than the current best match
                /// </remarks>
-               static int BetterFunction (EmitContext ec, ArrayList args, int argument_count,
-                                          MethodBase candidate, bool candidate_params,
-                                          MethodBase best, bool best_params, Location loc)
+               static bool BetterFunction (EmitContext ec, ArrayList args, int argument_count,
+                                           MethodBase candidate, bool candidate_params,
+                                           MethodBase best, bool best_params, Location loc)
                {
                        ParameterData candidate_pd = GetParameterData (candidate);
                        ParameterData best_pd = GetParameterData (best);
@@ -4297,31 +4311,26 @@ namespace Mono.CSharp {
                        //      }
                        //      
                        //      interface IFooBar : IFoo, IBar {}
-                       //
+                       //
                        // We cant tell if IFoo.DoIt is better than IBar.DoIt
                        //
                        // However, we have to consider that
                        // Trim (); is better than Trim (params char[] chars);
                         //
                        if (cand_count == 0 && argument_count == 0)
-                               return best_params ? 1 : 0;
+                               return !candidate_params && best_params;
 
                        if ((candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.PARAMS) &&
                            (candidate_pd.ParameterModifier (cand_count - 1) != Parameter.Modifier.ARGLIST))
                                if (cand_count != argument_count)
-                                       return 0;
-
-                       int rating1 = 0, rating2 = 0;
-
+                                       return false;
+                       
+                       bool better_at_least_one = false;
                        for (int j = 0; j < argument_count; ++j) {
-                               int x, y;
-                               
                                Argument a = (Argument) args [j];
 
-                               Type ct = TypeManager.TypeToCoreType (
-                                       candidate_pd.ParameterType (j));
-                               Type bt = TypeManager.TypeToCoreType (
-                                       best_pd.ParameterType (j));
+                               Type ct = candidate_pd.ParameterType (j);
+                               Type bt = best_pd.ParameterType (j);
 
                                if (candidate_pd.ParameterModifier (j) == Parameter.Modifier.PARAMS)
                                        if (candidate_params)
@@ -4331,14 +4340,17 @@ namespace Mono.CSharp {
                                        if (best_params)
                                                bt = TypeManager.GetElementType (bt);
 
-                               x = BetterConversion (ec, a, ct, bt, loc);
-                               y = BetterConversion (ec, a, bt, ct, loc);
+                               Type better = BetterConversion (ec, a, ct, bt, loc);
 
-                               if (x < y)
-                                       return 0;
+                               // for each argument, the conversion to 'ct' should be no worse than 
+                               // the conversion to 'bt'.
+                               if (better == bt)
+                                       return false;
                                
-                               rating1 += x;
-                               rating2 += y;
+                               // for at least one argument, the conversion to 'ct' should be better than 
+                               // the conversion to 'bt'.
+                               if (better == ct)
+                                       better_at_least_one = true;
                        }
 
                         //
@@ -4349,12 +4361,9 @@ namespace Mono.CSharp {
                         // force it to select the candidate
                         //
                         if (!candidate_params && best_params && cand_count == argument_count)
-                                return 1;
+                                return true;
 
-                       if (rating1 > rating2)
-                               return 1;
-                       else
-                               return 0;
+                       return better_at_least_one;
                }
 
                public static string FullMethodDesc (MethodBase mb)
@@ -4821,7 +4830,7 @@ namespace Mono.CSharp {
 
                                if (BetterFunction (ec, Arguments, arg_count, 
                                                    candidate, cand_params,
-                                                   method, method_params, loc) != 0) {
+                                                   method, method_params, loc)) {
                                        method = candidate;
                                        method_params = cand_params;
                                }
@@ -4839,10 +4848,10 @@ namespace Mono.CSharp {
                                         continue;
 
                                 bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate);
-                               if (BetterFunction (ec, Arguments, arg_count,
+                               if (!BetterFunction (ec, Arguments, arg_count,
                                                    method, method_params,
                                                    candidate, cand_params,
-                                                   loc) != 1) {
+                                                    loc)) {
                                        Report.SymbolRelatedToPreviousError (candidate);
                                        ambiguous = true;
                                }
@@ -5226,9 +5235,6 @@ namespace Mono.CSharp {
                        // First, resolve the expression that is used to
                        // trigger the invocation
                        //
-                       if (expr is BaseAccess)
-                               is_base = true;
-
                        if (expr is ConstructedType)
                                expr = ((ConstructedType) expr).GetSimpleName (ec);
 
@@ -5297,14 +5303,14 @@ namespace Mono.CSharp {
                        //
                        // Only base will allow this invocation to happen.
                        //
-                       if (is_base && method.IsAbstract){
+                       if (mg.IsBase && method.IsAbstract){
                                Report.Error (205, loc, "Cannot call an abstract base member: " +
                                              FullMethodDesc (method));
                                return null;
                        }
 
                        if (method.Name == "Finalize" && Arguments == null) {
-                               if (is_base)
+                               if (mg.IsBase)
                                        Report.Error (250, loc, "Do not directly call your base class Finalize method. It is called automatically from your destructor");
                                else
                                        Report.Error (245, loc, "Destructors and object.Finalize cannot be called directly. Consider calling IDisposable.Dispose if available");
@@ -5650,7 +5656,7 @@ namespace Mono.CSharp {
                {
                        MethodGroupExpr mg = (MethodGroupExpr) this.expr;
 
-                       EmitCall (ec, is_base, method.IsStatic, mg.InstanceExpression, method, Arguments, loc);
+                       EmitCall (ec, mg.IsBase, method.IsStatic, mg.InstanceExpression, method, Arguments, loc);
                }
                
                public override void EmitStatement (EmitContext ec)
@@ -5685,9 +5691,9 @@ namespace Mono.CSharp {
                        //
                        // First try to resolve it as a cast.
                        //
-                       type = ec.DeclSpace.ResolveType (expr, true, loc);
-                       if (type != null) {
-                               Cast cast = new Cast (new TypeExpression (type, loc), argument, loc);
+                       TypeExpr te = expr.ResolveAsTypeTerminal (ec, true);
+                       if (te != null) {
+                               Cast cast = new Cast (te, argument, loc);
                                return cast.Resolve (ec);
                        }
 
@@ -5732,8 +5738,8 @@ namespace Mono.CSharp {
                        //
                        // First try to resolve it as a cast.
                        //
-                       type = ec.DeclSpace.ResolveType (expr, true, loc);
-                       if (type != null) {
+                       TypeExpr te = expr.ResolveAsTypeTerminal (ec, true);
+                       if (te != null) {
                                error201 ();
                                return null;
                        }
@@ -5868,11 +5874,12 @@ namespace Mono.CSharp {
                                return this;
                        }
                        
-                       type = ec.DeclSpace.ResolveType (RequestedType, false, loc);
-                       
-                       if (type == null)
+                       RequestedType = RequestedType.ResolveAsTypeTerminal (ec, false);
+                       if (RequestedType == null)
                                return null;
                        
+                       type = RequestedType.Type;
+                       
                        CheckObsoleteAttribute (type);
 
                        bool IsDelegate = TypeManager.IsDelegateType (type);
@@ -7109,7 +7116,7 @@ namespace Mono.CSharp {
        ///   Implements the typeof operator
        /// </summary>
        public class TypeOf : Expression {
-               public readonly Expression QueriedType;
+               public Expression QueriedType;
                protected Type typearg;
                
                public TypeOf (Expression queried_type, Location l)
@@ -7120,11 +7127,12 @@ namespace Mono.CSharp {
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       typearg = ec.DeclSpace.ResolveType (QueriedType, false, loc);
-
-                       if (typearg == null)
+                       QueriedType = QueriedType.ResolveAsTypeTerminal (ec, false);
+                       if (QueriedType == null)
                                return null;
 
+                       typearg = QueriedType.Type;
+
                        if (typearg == TypeManager.void_type) {
                                Error (673, "System.Void cannot be used from C# - " +
                                       "use typeof (void) to get the void type object");
index 7808411ab9d21215e073a4186bfbfa6bc1a94b1a..96ef6b4550d0cfef73034d468bf4327a4f9be54c 100644 (file)
@@ -1195,7 +1195,7 @@ namespace Mono.CSharp {
                        int num_args;
 
                        SimpleName sn = new SimpleName (name, loc);
-                       TypeExpr resolved = sn.ResolveAsTypeTerminal (ec);
+                       TypeExpr resolved = sn.ResolveAsTypeTerminal (ec, true);
                        if ((resolved == null) || (resolved.Type == null)) {
                                Report.Error (246, loc,
                                              "The type or namespace name `{0}<...>' "+
index bdc2eb4f4b0e67f0ac6fe59bc99e128d796875ed..03322aa35a8b12ce805f11a39a5aaca660f7134e 100755 (executable)
@@ -365,12 +365,11 @@ namespace Mono.CSharp {
                        if (using_clauses == null)
                                using_clauses = new ArrayList ();
 
-                       if (RootContext.WarningLevel >= 3) {
-                               foreach (UsingEntry old_entry in using_clauses){
-                                       if (old_entry.Name == ns){
+                       foreach (UsingEntry old_entry in using_clauses) {
+                               if (old_entry.Name == ns) {
+                                       if (RootContext.WarningLevel >= 3)
                                                Report.Warning (105, loc, "The using directive for '{0}' appeared previously in this namespace", ns);
                                                return;
-                                       }
                                }
                        }