[mcs] Add compilergenerated attribute for private event backing fields to match newer csc
authorMarek Safar <marek.safar@gmail.com>
Wed, 21 Sep 2016 10:53:12 +0000 (12:53 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 21 Sep 2016 10:54:08 +0000 (12:54 +0200)
mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/DynamicContext.cs
mcs/mcs/import.cs
mcs/mcs/property.cs
mcs/tests/test-254.cs
mcs/tests/ver-il-net_4_x.xml

index 9c466c5ed9c9875b31f69f0f0ec9654075f3ac37..d03145e0df346c783650a15ff080a963e4ddcbda 100644 (file)
@@ -93,7 +93,8 @@ namespace Microsoft.CSharp.RuntimeBinder
                                module.SetDeclaringAssembly (temp);
 
                                var importer = new Compiler.ReflectionImporter (module, cc.BuiltinTypes) {
-                                       IgnorePrivateMembers = false
+                                       IgnorePrivateMembers = false,
+                                       IgnoreCompilerGeneratedField = false
                                };
 
                                // Import all currently loaded assemblies
index 60073b9f4c1338929c6098c9a28f861d36534132..9518427e1a17c1fe1499516410ea4c9fde28a893 100644 (file)
@@ -142,6 +142,7 @@ namespace Mono.CSharp
                        compiled_types = new Dictionary<MetaType, TypeSpec> (40, ReferenceEquality<MetaType>.Default);
                        assembly_2_definition = new Dictionary<Assembly, IAssemblyDefinition> (ReferenceEquality<Assembly>.Default);
                        IgnorePrivateMembers = true;
+                       IgnoreCompilerGeneratedField = true;
                }
 
                #region Properties
@@ -154,6 +155,8 @@ namespace Mono.CSharp
 
                public bool IgnorePrivateMembers { get; set; }
 
+               public bool IgnoreCompilerGeneratedField { get; set; }
+
                #endregion
 
                public abstract void AddCompiledType (TypeBuilder builder, TypeSpec spec);
@@ -179,8 +182,10 @@ namespace Mono.CSharp
                                        break;
                                default:
                                        // Ignore private fields (even for error reporting) to not require extra dependencies
-                                       if ((IgnorePrivateMembers && !declaringType.IsStruct) ||
-                                               HasAttribute (CustomAttributeData.GetCustomAttributes (fi), "CompilerGeneratedAttribute", CompilerServicesNamespace))
+                                       if (IgnorePrivateMembers && !declaringType.IsStruct)
+                                               return null;
+
+                                       if (IgnoreCompilerGeneratedField && HasAttribute (CustomAttributeData.GetCustomAttributes (fi), "CompilerGeneratedAttribute", CompilerServicesNamespace))
                                                return null;
 
                                        mod = Modifiers.PRIVATE;
index 8036f2c1126a56319198464e021386325110ca10..6b1990e1f0983d87bd8b91d0f60dee7efe51129c 100644 (file)
@@ -1210,12 +1210,11 @@ namespace Mono.CSharp
 
                        backing_field = new Field (Parent,
                                new TypeExpression (MemberType, Location),
-                               Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
+                               Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
                                MemberName, null);
 
                        Parent.PartialContainer.Members.Add (backing_field);
                        backing_field.Initializer = Initializer;
-                       backing_field.ModFlags &= ~Modifiers.COMPILER_GENERATED;
 
                        // Call define because we passed fields definition
                        backing_field.Define ();
index 1971d2f4e4812fa82feb8fbed1c666537ce0a723..36453ea86b397061250c48d9d7b086bc1dca1d8d 100644 (file)
@@ -1,5 +1,6 @@
 using System;
 using System.Reflection;
+using System.Runtime.CompilerServices;
 
 [assembly: Test]
 
@@ -130,7 +131,8 @@ public class ClassMain
                Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), false, 44);
                Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 45);
                FieldInfo fi = typeof(Test_3).GetField ("e_1", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
-               Assert (fi.GetCustomAttributes (true), true, 46);
+               Assert (fi.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true), true, 46);
+               Assert (fi.GetCustomAttributes (typeof (TestAttribute), true), true, 47);
 
                ei = typeof(Test_3).GetEvent ("e_2");
                Assert (ei.GetCustomAttributes (true), false, 51);
@@ -139,7 +141,8 @@ public class ClassMain
                Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), true, 54);
                Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 55);
                fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
-               Assert (fi.GetCustomAttributes (true), false, 56);
+               Assert (fi.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true), true, 56);
+               Assert (fi.GetCustomAttributes (typeof (TestAttribute), true), false, 57);
 
                ei = typeof(Test_4).GetEvent ("e_2");
                Assert (ei.GetCustomAttributes (true), false, 71);
@@ -148,7 +151,8 @@ public class ClassMain
                Assert (ei.GetRemoveMethod ().GetCustomAttributes (true), false, 74);
                Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), true, 75);
                fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
-               Assert (fi.GetCustomAttributes (true), false, 76);
+               Assert (fi.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true), true, 76);
+               Assert (fi.GetCustomAttributes (typeof (TestAttribute), true), false, 77);
 
                ei = typeof(Test_4).GetEvent ("e_3");
                Assert (ei.GetCustomAttributes (true), false, 81);
@@ -159,7 +163,8 @@ public class ClassMain
                Assert (ei.GetRemoveMethod ().ReturnTypeCustomAttributes.GetCustomAttributes (true), false, 86);
                Assert (ei.GetRemoveMethod ().GetParameters ()[0].GetCustomAttributes (true), true, 87);
                fi = typeof(Test_3).GetField ("e_2", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
-               Assert (fi.GetCustomAttributes (true), false, 88);
+               Assert (fi.GetCustomAttributes (typeof (CompilerGeneratedAttribute), true), true, 86);
+               Assert (fi.GetCustomAttributes (typeof (TestAttribute), true), false, 87);
 
                return failed ? 1 : 0;
        }
index 0cbfab7639446a263dbd2ddf710b6179d65babaa..df5884f7fe914d2177021945f3f5aebe91ca4cc1 100644 (file)
         <size>80</size>
       </method>
       <method name="Int32 Main()" attrs="150">
-        <size>1169</size>
+        <size>1309</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>