2010-06-03 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Thu, 3 Jun 2010 07:34:45 +0000 (07:34 -0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 3 Jun 2010 07:34:45 +0000 (07:34 -0000)
A fix for bug #610919
* parameter.cs, property.cs, cs-parser.jay: Use independent implicit
parameters for explicit event accessors. Anonymous method capturing
won't otherwise work for event implicit parameter.

svn path=/trunk/mcs/; revision=158383

mcs/mcs/ChangeLog
mcs/mcs/cs-parser.jay
mcs/mcs/parameter.cs
mcs/mcs/property.cs

index 1d712fd43d4bfe2b4ab994a7d7d1ca9699e7ac36..477460f1911667f0a9c9b15d6101218992ae23a8 100644 (file)
@@ -1,3 +1,10 @@
+2010-06-03  Marek Safar  <marek.safar@gmail.com>
+
+       A fix for bug #610919
+       * parameter.cs, property.cs, cs-parser.jay: Use independent implicit
+       parameters for explicit event accessors. Anonymous method capturing
+       won't otherwise work for event implicit parameter.
+
 2010-06-02  Marek Safar  <marek.safar@gmail.com>
 
        A fix for bug #610088
index adccfdf4da46cdb75f6113233ba148aefd1cf8d9..20af9defc05b38a6558279ea3a7aa22c2d154743 100644 (file)
@@ -1804,15 +1804,13 @@ get_accessor_declaration
 set_accessor_declaration
        : opt_attributes opt_modifiers SET 
          {
-               Parameter implicit_value_parameter = new Parameter (
-                       implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null, GetLocation ($3));
-
                if (!parsing_indexer) {
-                       current_local_parameters = new ParametersCompiled (compiler, new Parameter [] { implicit_value_parameter });
+                       current_local_parameters = ParametersCompiled.CreateImplicitParameter (implicit_value_parameter_type, GetLocation ($3));
                } else {
                        current_local_parameters = ParametersCompiled.MergeGenerated (compiler,
-                               indexer_parameters, true, implicit_value_parameter, null);
+                               indexer_parameters, true, new Parameter (
+                                       implicit_value_parameter_type, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
+                                       null);
                }
                
                lexer.PropertyParsing = false;
@@ -2270,10 +2268,6 @@ event_declaration
          OPEN_BRACE
          {
                implicit_value_parameter_type = (FullNamedExpression) $4;  
-               current_local_parameters = new ParametersCompiled (compiler,
-                       new Parameter (implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null, GetLocation ($3)));
-
                lexer.EventParsing = true;
          }
          event_accessor_declarations
@@ -2344,19 +2338,20 @@ event_accessor_declarations
                Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
                $$ = null;
          }
-       | { $$ = null; }
        ;
 
 add_accessor_declaration
        : opt_attributes ADD
          {
                lexer.EventParsing = false;
+               current_local_parameters = ParametersCompiled.CreateImplicitParameter (implicit_value_parameter_type, GetLocation ($2));
          }
          block
          {
-               Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, GetLocation ($2));
+               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, current_local_parameters, GetLocation ($2));
+         
                lexer.EventParsing = true;
-               $$ = accessor;
+               current_local_parameters = null;        
          }
        | opt_attributes ADD error {
                Report.Error (73, GetLocation ($2), "An add or remove accessor must have a body");
@@ -2372,11 +2367,14 @@ remove_accessor_declaration
        : opt_attributes REMOVE
          {
                lexer.EventParsing = false;
+               current_local_parameters = ParametersCompiled.CreateImplicitParameter (implicit_value_parameter_type, GetLocation ($2));
          }
          block
-         {
-               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, GetLocation ($2));
+         {  
+               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, current_local_parameters, GetLocation ($2));
+               
                lexer.EventParsing = true;
+               current_local_parameters = null;                
          }
        | opt_attributes REMOVE error {
                Report.Error (73, GetLocation ($2), "An add or remove accessor must have a body");
index 8cc781a5e530a0919b284c111a72348b2a49d24b..6d2144cee73c79798d4aa8ac1f97939cf3926c8e 100644 (file)
@@ -1090,6 +1090,13 @@ namespace Mono.CSharp {
                        return new ParametersCompiled (pd, types);
                }
 
+               public static ParametersCompiled CreateImplicitParameter (FullNamedExpression texpr, Location loc)
+               {
+                       return new ParametersCompiled (
+                               new[] { new Parameter (texpr, "value", Parameter.Modifier.NONE, null, loc) },
+                               null);
+               }
+
                //
                // Returns non-zero value for equal CLS parameter signatures
                //
index ec2067d7e23b37bd79b424ce3cf9cb910368e896..b90cd51dbf51167b454a61a569fa09385964937f 100644 (file)
@@ -240,8 +240,7 @@ namespace Mono.CSharp
                        public SetMethod (PropertyBase method) :
                                base (method, "set_")
                        {
-                               parameters = new ParametersCompiled (Compiler,
-                                       new Parameter (method.type_expr, "value", Parameter.Modifier.NONE, null, Location));
+                               parameters = ParametersCompiled.CreateImplicitParameter (method.type_expr, Location);
                        }
 
                        public SetMethod (PropertyBase method, Accessor accessor):
@@ -1028,6 +1027,7 @@ namespace Mono.CSharp
                {
                        protected readonly Event method;
                        ImplicitParameter param_attr;
+                       ParametersCompiled parameters;
 
                        static readonly string[] attribute_targets = new string [] { "method", "param", "return" };
 
@@ -1039,6 +1039,7 @@ namespace Mono.CSharp
                        {
                                this.method = method;
                                this.ModFlags = method.ModFlags;
+                               this.parameters = ParametersCompiled.CreateImplicitParameter (method.type_expr, Location);
                        }
 
                        protected AEventAccessor (Event method, Accessor accessor, string prefix)
@@ -1046,6 +1047,7 @@ namespace Mono.CSharp
                        {
                                this.method = method;
                                this.ModFlags = method.ModFlags;
+                               this.parameters = accessor.Parameters;
                        }
 
                        public bool IsInterfaceImplementation {
@@ -1087,6 +1089,8 @@ namespace Mono.CSharp
 
                        public virtual MethodBuilder Define (DeclSpace parent)
                        {
+                               parameters.Resolve (this);
+
                                method_data = new MethodData (method, method.ModFlags,
                                        method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
 
@@ -1120,7 +1124,7 @@ namespace Mono.CSharp
 
                        public override ParametersCompiled ParameterInfo {
                                get {
-                                       return method.parameters;
+                                       return parameters;
                                }
                        }
                }
@@ -1147,8 +1151,6 @@ namespace Mono.CSharp
                public EventBuilder     EventBuilder;
                public MethodBuilder AddBuilder, RemoveBuilder;
 
-               ParametersCompiled parameters;
-
                protected Event (DeclSpace parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
                        : base (parent, null, type, mod_flags,
                                parent.PartialContainer.Kind == MemberKind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
@@ -1198,9 +1200,6 @@ namespace Mono.CSharp
                                Report.Error (66, Location, "`{0}': event must be of a delegate type", GetSignatureForError ());
                        }
 
-                       parameters = ParametersCompiled.CreateFullyResolved (
-                               new Parameter (null, "value", Parameter.Modifier.NONE, null, Location), MemberType);
-
                        if (!CheckBase ())
                                return false;