Author: kumpera
Date: 2007-07-11 15:52:35 -0400 (Wed, 11 Jul 2007)
New Revision: 81829
Modified:
trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog
trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
trunk/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
Log:
In System.Reflection.Emit:
2007-07-11 Rodrigo Kumpera <[EMAIL PROTECTED]>
* TypeBuilder.cs (CreateType): method did not check for enum type with
defined methods and fixed compatibility issue in case of calling CreateType
again after the first one failed, it now returns null as well.
In Test/System.Reflection.Emit:
2007-07-11 Rodrigo Kumpera <[EMAIL PROTECTED]>
* TypeBuilderTest.cs: Added tests for enum creation. These tests are
related to bugs #82018 and #82075
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog 2007-07-11
19:41:14 UTC (rev 81828)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog 2007-07-11
19:52:35 UTC (rev 81829)
@@ -1,3 +1,7 @@
+2007-07-11 Rodrigo Kumpera <[EMAIL PROTECTED]>
+
+ * TypeBuilder.cs (CreateType): method did not check for enum type with
defined methods and fixed compatibility issue in case of calling CreateType
again after the first one failed, it now returns null as well.
+
2007-07-10 Zoltan Varga <[EMAIL PROTECTED]>
* OpCodeType.cs EventToken.cs FieldToken.cs SignatureToken.cs
PackingSize.cs
Modified: trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
2007-07-11 19:41:14 UTC (rev 81828)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
2007-07-11 19:52:35 UTC (rev 81829)
@@ -82,6 +82,7 @@
private Type created;
#endregion
string fullname;
+ bool createTypeCalled;
public const int UnspecifiedTypeSize = 0;
@@ -723,7 +724,7 @@
public Type CreateType()
{
/* handle nesting_type */
- if (created != null)
+ if (createTypeCalled)
return created;
if (!IsInterface && (parent == null) && (this !=
pmodule.assemblyb.corlib_object_type) && (FullName != "<Module>")) {
@@ -757,6 +758,9 @@
if ((parent != null) && parent.IsSealed)
throw new TypeLoadException ("Could not load
type '" + FullName + "' from assembly '" + Assembly + "' because the parent
type is sealed.");
+ if (parent == pmodule.assemblyb.corlib_enum_type &&
methods != null)
+ throw new TypeLoadException ("Could not load
type '" + FullName + "' from assembly '" + Assembly + "' because it is an enum
with methods.");
+
if (methods != null) {
for (int i = 0; i < num_methods; ++i)
((MethodBuilder)(methods[i])).fixup ();
@@ -773,7 +777,8 @@
foreach (ConstructorBuilder ctor in ctors)
ctor.fixup ();
}
-
+
+ createTypeCalled = true;
created = create_runtime_class (this);
if (created != null)
return created;
Modified: trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
2007-07-11 19:41:14 UTC (rev 81828)
+++ trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
2007-07-11 19:52:35 UTC (rev 81829)
@@ -1,3 +1,7 @@
+2007-07-11 Rodrigo Kumpera <[EMAIL PROTECTED]>
+
+ * TypeBuilderTest.cs: Added tests for enum creation. These tests are
related to bugs #82018 and #82075
+
2007-07-06 Gert Driesen <[EMAIL PROTECTED]>
* TypeBuilderTest.cs: Improved tests for SetParent.
Modified: trunk/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
2007-07-11 19:41:14 UTC (rev 81828)
+++ trunk/mcs/class/corlib/Test/System.Reflection.Emit/TypeBuilderTest.cs
2007-07-11 19:52:35 UTC (rev 81829)
@@ -30,6 +30,14 @@
namespace MonoTests.System.Reflection.Emit
{
+ public interface EmptyInterface {
+
+ }
+
+ public interface OneMethodInterface {
+ void foo ();
+ }
+
[TestFixture]
public class TypeBuilderTest
{
@@ -235,6 +243,345 @@
}
[Test]
+ public void TestEnumWithoutValueFieldThrowsException () //bug
82018
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum1",
+ TypeAttributes.Sealed |
TypeAttributes.Serializable,
+ typeof (Enum));
+
+ try {
+ tb.CreateType ();
+ Assert.Fail ("#1: must throw
TypeLoadException");
+ } catch (TypeLoadException e) {
+ }
+ }
+
+ [Test]
+ public void TestCreateTypeReturnsNullOnSecondCallForBadType ()
//bug 82018
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum2",
+ TypeAttributes.Sealed |
TypeAttributes.Serializable,
+ typeof (Enum));
+
+ try {
+ tb.CreateType ();
+ Assert.Fail ("#1: must throw
TypeLoadException");
+ } catch (TypeLoadException e) {
+ }
+
+ Assert.IsNull (tb.CreateType ());
+ }
+
+ [Test]
+ public void TestEnumWithEmptyInterfaceBuildsOk ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum3",
+ TypeAttributes.Sealed |
TypeAttributes.Serializable,
+ typeof (Enum));
+ tb.DefineField ("value__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ tb.AddInterfaceImplementation ( typeof
(EmptyInterface));
+
+ try {
+ tb.CreateType ();
+ } catch (TypeLoadException e) {
+ Assert.Fail ("#1: must build enum type ok");
+ }
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestEnumWithNonEmptyInterfaceBuildsFails ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum4",
+ TypeAttributes.Sealed |
TypeAttributes.Serializable,
+ typeof (Enum));
+ tb.DefineField ("value__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ tb.AddInterfaceImplementation ( typeof
(OneMethodInterface));
+
+ try {
+ tb.CreateType ();
+ Assert.Fail ("#1: type doesn't have all
interface methods");
+ } catch (TypeLoadException e) {
+ }
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestTypeDontImplementInterfaceMethodBuildsFails ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum4",
+ TypeAttributes.Sealed |
TypeAttributes.Serializable,
+ typeof (object));
+
+ tb.AddInterfaceImplementation ( typeof
(OneMethodInterface));
+
+ try {
+ tb.CreateType ();
+ Assert.Fail ("#1: type doesn't have all
interface methods");
+ } catch (TypeLoadException e) {
+ }
+ }
+
+ [Test]
+ public void TestEnumWithSequentialLayoutBuildsFails ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum5",
+ TypeAttributes.Sealed | TypeAttributes.Serializable |
TypeAttributes.SequentialLayout,
+ typeof (Enum));
+ tb.DefineField ("value__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ try {
+ tb.CreateType ();
+ Assert.Fail ("#1: type doesn't have all
interface methods");
+ } catch (TypeLoadException e) {
+ }
+ }
+
+ [Test]
+ public void TestEnumWithExplicitLayoutBuildsFails ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum6",
+ TypeAttributes.Sealed | TypeAttributes.Serializable |
TypeAttributes.ExplicitLayout,
+ typeof (Enum));
+ tb.DefineField ("value__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ try {
+ tb.CreateType ();
+ Assert.Fail ("#1: type doesn't have all
interface methods");
+ } catch (TypeLoadException e) {
+ }
+ }
+
+ [Test]
+ public void TestEnumWithMethodsBuildFails ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum7",
+ TypeAttributes.Sealed |
TypeAttributes.Serializable,
+ typeof (Enum));
+ tb.DefineField ("value__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ MethodBuilder methodBuilder = tb.DefineMethod("mmm",
+ MethodAttributes.Public |
MethodAttributes.Virtual,
+ null,
+ new Type[] { });
+
+ methodBuilder.GetILGenerator().Emit(OpCodes.Ret);
+ try {
+ tb.CreateType ();
+ Assert.Fail ("#1: enum has method");
+ } catch (TypeLoadException e) {
+ }
+ }
+
+
+ [Test]
+ public void TestEnumWithBadTypeValueFieldBuildFails ()
+ {
+ Type[] badTypes = {
+ typeof (object),
+ typeof (string),
+ typeof (DateTime)
+ };
+
+ foreach (Type type in badTypes) {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum8",
+ TypeAttributes.Sealed |
TypeAttributes.Serializable,
+ typeof (Enum));
+ tb.DefineField ("value__", type,
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ try {
+ tb.CreateType ();
+ Assert.Fail ("enum using bad type: " +
type);
+ } catch (TypeLoadException e) {
+ }
+ }
+ }
+
+ [Test]
+ public void TestEnumWithGoodTypeValueFieldBuildOk ()
+ {
+ Type[] goodTypes = {
+ typeof (byte),typeof (sbyte),typeof (bool),
+ typeof (ushort),typeof (short),typeof (char),
+ typeof (uint),typeof (int),
+ typeof (ulong),typeof (long),
+ typeof (UIntPtr),typeof (IntPtr),
+ };
+
+ foreach (Type type in goodTypes) {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum9",
+ TypeAttributes.Sealed |
TypeAttributes.Serializable,
+ typeof (Enum));
+ tb.DefineField ("value__", type,
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ try {
+ tb.CreateType ();
+ } catch (TypeLoadException e) {
+ Assert.Fail ("enum using good type: " +
type);
+ }
+ }
+ }
+
+ [Test]
+ public void TestEnumWithMultipleValueFieldsBuildFals ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum10",
+ TypeAttributes.Sealed | TypeAttributes.Serializable,
+ typeof (Enum));
+ tb.DefineField ("value__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+ tb.DefineField ("value2__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ try {
+ tb.CreateType ();
+ Assert.Fail ("#1: invalid enum type");
+ } catch (TypeLoadException e) {
+ }
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestEnumWithEmptyInterfaceCanBeCasted ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum11",
+ TypeAttributes.Sealed | TypeAttributes.Serializable,
+ typeof (Enum));
+ tb.DefineField ("value__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ tb.AddInterfaceImplementation ( typeof
(EmptyInterface));
+
+ try {
+ tb.CreateType ();
+ } catch (TypeLoadException e) {
+ Assert.Fail ("#1: must build enum type ok");
+ }
+
+ try {
+ EmptyInterface obj = (EmptyInterface)
Activator.CreateInstance (tb);
+ } catch (TypeLoadException e) {
+ Assert.Fail ("#2: must cast enum to interface");
+ }
+ }
+
+ [Test]
+ public void TestEnumWithValueFieldBuildOk ()
+ {
+ AssemblyName name = new AssemblyName ();
+ name.Name = "foo";
+
+ AssemblyBuilder asm =
AppDomain.CurrentDomain.DefineDynamicAssembly (name,
+ AssemblyBuilderAccess.Run |
AssemblyBuilderAccess.Save);
+ ModuleBuilder module = asm.DefineDynamicModule
("foo.dll", "foo.dll", true);
+
+ TypeBuilder tb = module.DefineType ("FooEnum12",
+ TypeAttributes.Sealed | TypeAttributes.Serializable,
+ typeof (Enum));
+ tb.DefineField ("value__", typeof (int),
FieldAttributes.SpecialName |
+ FieldAttributes.Private |
FieldAttributes.RTSpecialName);
+
+ try {
+ tb.CreateType ();
+ } catch (TypeLoadException e) {
+ Assert.Fail ("#1: must build enum type ok");
+ }
+ }
+
+ [Test]
public void TestIsAbstract ()
{
TypeBuilder tb = module.DefineType (genTypeName ());
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches