[Mono-bugs] [Bug 75366][Maj] New - S.R.E. generates incorrect references to derived fields

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Jun 23 12:51:58 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by nazgul at omega.pl.

http://bugzilla.ximian.com/show_bug.cgi?id=75366

--- shadow/75366	2005-06-23 12:51:58.000000000 -0400
+++ shadow/75366.tmp.9972	2005-06-23 12:51:58.000000000 -0400
@@ -0,0 +1,97 @@
+Bug#: 75366
+Product: Mono: Runtime
+Version: 1.0
+OS: 
+OS Details: mono svn 23.06.2005
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: misc
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: nazgul at omega.pl               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: S.R.E. generates incorrect  references to derived fields
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+When you load all members (including derived ones) with
+System.Type.GetMembers and then use obtained MemberInfos to emit assembly,
+then references to fields are incorrect in generated IL. 
+
+Steps to reproduce the problem:
+1. Compile following library with mcs tlib.cs /t:library /out:a.dll
+
+class A {
+   public int foo;
+}
+class B : A {}
+
+
+2. Compile S.R.E program 
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+
+class M {
+         static void Main () {
+         AssemblyName name = new AssemblyName();
+            name.Name = "o";
+            AssemblyBuilder builder =
+AppDomain.CurrentDomain.DefineDynamicAssembly(name,
+AssemblyBuilderAccess.RunAndSave);
+            ModuleBuilder mb = builder.DefineDynamicModule("out", "bla.dll");
+
+            TypeBuilder tb = mb.DefineType("MyClass");
+            
+            ConstructorBuilder constructorBuilder =
+tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard,
+null);
+            ILGenerator ilGenerator = constructorBuilder.GetILGenerator();
+
+            MemberInfo[] mems =
+Assembly.LoadFrom("a.dll").GetType("B").GetMembers(BindingFlags.Public |
+BindingFlags.Instance);
+            foreach (MemberInfo m in mems)
+              if (m.Name == "foo")
+                ilGenerator.Emit(OpCodes.Ldfld, (FieldInfo) m);
+
+            ilGenerator.Emit (OpCodes.Pop);
+            ilGenerator.Emit(OpCodes.Ret);
+
+            tb.CreateType();
+
+            builder.Save("bla.dll");
+         }
+} 
+
+3. Run mono t.exe
+4. monodis bla.dll
+
+Actual Results:
+...
+        IL_0000:  ldfld  int32 [a]B::foo
+        IL_0005:  pop 
+        IL_0006:  ret 
+...
+
+Expected Results:
+...
+        IL_0000:  ldfld  int32 [a]A::foo
+        IL_0005:  pop 
+        IL_0006:  ret 
+...
+
+
+How often does this happen? 
+Always
+
+Additional Information:
+I'm setting priority of this bug to Major, because it blocks running code
+generated by nemerle compiler on MS.NET (the workarounds are possible, but
+not easy to implement, so we would prefer mono to behave correctly there...)


More information about the mono-bugs mailing list