* TabControl.cs: Fix typo, emilinates an unneeded expose event.
[mono.git] / mcs / mcs / parameter.cs
old mode 100755 (executable)
new mode 100644 (file)
index daf40eb..d70dd2d
@@ -31,12 +31,10 @@ namespace Mono.CSharp {
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
                        if (a.Type == TypeManager.marshal_as_attr_type) {
-                               UnmanagedMarshal marshal = a.GetMarshal ();
+                               UnmanagedMarshal marshal = a.GetMarshal (this);
                                if (marshal != null) {
                                        builder.SetMarshal (marshal);
-                                       return;
                                }
-                               Report.Warning (-24, a.Location, "The Microsoft Runtime cannot set this marshal info. Please use the Mono runtime instead.");
                                return;
                        }
 
@@ -71,6 +69,10 @@ namespace Mono.CSharp {
 
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
                {
+                       if (a.Type == TypeManager.cls_compliant_attribute_type) {
+                               Report.Warning (3023, 1, a.Location, "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
+                       }
+
                        // This occurs after Warning -28
                        if (builder == null)
                                return;
@@ -144,6 +146,8 @@ namespace Mono.CSharp {
                public readonly Modifier ModFlags;
                public readonly string Name;
                Type parameter_type;
+
+               EmitContext ec;  // because ApplyAtrribute doesn't have ec
                
                public Parameter (Expression type, string name, Modifier mod, Attributes attrs)
                        : base (attrs)
@@ -155,10 +159,27 @@ namespace Mono.CSharp {
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
+                       if (a.Type == TypeManager.in_attribute_type && Attributes == ParameterAttributes.Out) {
+                               Report.Error (36, a.Location, "Can not use [In] attribute on out parameter");
+                               return;
+                       }
+
                        if (a.Type == TypeManager.param_array_type) {
                                Report.Error (674, a.Location, "Do not use 'System.ParamArrayAttribute'. Use the 'params' keyword instead");
                                return;
                        }
+
+                       if (a.Type == TypeManager.out_attribute_type && (ModFlags & Modifier.REF) != 0 &&
+                           !OptAttributes.Contains (TypeManager.in_attribute_type, ec)) {
+                               Report.Error (662, a.Location,
+                                       "'{0}' cannot specify only Out attribute on a ref parameter. Use both In and Out attributes, or neither", GetSignatureForError ());
+                               return;
+                       }
+
+                       if (a.Type == TypeManager.cls_compliant_attribute_type) {
+                               Report.Warning (3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
+                       }
+
                        base.ApplyAttributeBuilder (a, cb);
                }
 
@@ -167,6 +188,8 @@ namespace Mono.CSharp {
                // </summary>
                public bool Resolve (EmitContext ec, Location l)
                {
+                       this.ec = ec;
+
                        TypeExpr texpr = TypeName.ResolveAsTypeTerminal (ec, false);
                        if (texpr == null)
                                return false;
@@ -179,7 +202,7 @@ namespace Mono.CSharp {
                        }
 
                        if (parameter_type == TypeManager.void_type){
-                               Report.Error (1536, l, "`void' parameter is not permitted");
+                               Report.Error (1536, l, "Invalid parameter type 'void'");
                                return false;
                        }
 
@@ -279,11 +302,6 @@ namespace Mono.CSharp {
                                        
                        if (OptAttributes != null) {
                                OptAttributes.Emit (ec, this);
-       
-                               if (par_attr == ParameterAttributes.Out){
-                                       if (OptAttributes.Contains (TypeManager.in_attribute_type, ec))
-                                               Report.Error (36, loc,  "Can not use [In] attribute on out parameter");
-                               }
                        }
                }
 
@@ -486,19 +504,6 @@ namespace Mono.CSharp {
 
                        return true;
                }
-
-               //
-               // This variant is used by Delegates, because they need to
-               // resolve/define names, instead of the plain LookupType
-               //
-               public bool ComputeAndDefineParameterTypes (EmitContext ec)
-               {
-                       bool old_type_resolving = ec.ResolvingTypeTree;
-                       ec.ResolvingTypeTree = true;
-                       bool retval = ComputeParameterTypes (ec);
-                       ec.ResolvingTypeTree = old_type_resolving;
-                       return retval;
-               }
                
                /// <summary>
                ///   Returns the argument types as an array