In mcs:
authorRaja R Harinath <harinath@hurrynot.org>
Fri, 1 Apr 2005 14:27:58 +0000 (14:27 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Fri, 1 Apr 2005 14:27:58 +0000 (14:27 -0000)
2005-04-01  Raja R Harinath  <rharinath@novell.com>

Fix #74232 and cs0208-3.cs.
* expression.cs (ComposedCast.DoResolveAsTypeStep): Add CS0208 check.
* typemanager.cs (IsUnmanagedType): Don't allow 'object' as an
unmanaged type.  Don't use FieldBuilders when 't' is a
TypeBuilder.  Use ModFlags and MemberType fields.
* class.cs (MemberBase.member_type): Rename from MemberType.
(MemberBase.MemberType): New property.  Determines member_type on
demand.
(MemberBase.DoDefine): Don't initialize MemberType here.
(FieldMember.Define): Likewise.

In errors:
* TestRunner.cs (TestRunner): Make "KNOWN ISSUE" messages slightly
more verbose.
* cs0208-4.cs: New test from #74232.

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

mcs/errors/ChangeLog
mcs/errors/TestRunner.cs
mcs/errors/cs0208-4.cs [new file with mode: 0644]
mcs/errors/gmcs-expect-no-error
mcs/errors/known-issues-mcs
mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/expression.cs
mcs/mcs/typemanager.cs

index fb2cc34bc88b41fdf77950610a5b7494dae866b0..d5e2f758a9c2dc13e5ff5a0ea95e56728c090543 100644 (file)
@@ -1,5 +1,9 @@
 2005-04-01  Raja R Harinath  <rharinath@novell.com>
 
+       * TestRunner.cs (TestRunner): Make "KNOWN ISSUE" messages slightly
+       more verbose.
+       * cs0208-4.cs: New test from #74232.
+
        * cs0267.cs: New.  Mentioned in passing in #74309.
 
 2005-03-29  Raja R Harinath  <rharinath@novell.com>
index d6701ec4273bd6cc98c3323eff479575f841b86f..00e3cf06cf0de9c10ed0fd8a00d9941a3f3f61e1 100644 (file)
@@ -273,7 +273,7 @@ namespace TestRunner {
 
                                case CompilerError.Wrong:
                                        if (know_issues.Contains (file)) {
-                                               LogLine ("KNOWN ISSUE");
+                                               LogLine ("KNOWN ISSUE (Wrong error reported)");
                                                know_issues.Remove (file);
                                                return false;
                                        }
@@ -289,7 +289,7 @@ namespace TestRunner {
 
                                case CompilerError.Missing:
                                        if (no_error_list.Contains (file)) {
-                                               LogLine ("KNOW ISSUE");
+                                               LogLine ("KNOWN ISSUE (No error reported)");
                                                no_error_list.Remove (file);
                                                return false;
                                        }
diff --git a/mcs/errors/cs0208-4.cs b/mcs/errors/cs0208-4.cs
new file mode 100644 (file)
index 0000000..8467340
--- /dev/null
@@ -0,0 +1,15 @@
+// cs0208-4.cs: Cannot declare a pointer to a managed type ('System.Object')
+// Line: 11
+// Compiler options: -unsafe
+
+using System;
+using System.Runtime.InteropServices;
+
+class C
+{
+       [DllImport ("xml2")]
+       unsafe static extern object* valuePop (IntPtr context);
+       public static void Main ()
+       {
+       }
+}
index 6b7888369f8cb84d15327b1b51d6662ad6738059..c6de6e1d7b5b9823beac061f58a0497e0d20de61 100644 (file)
@@ -20,6 +20,7 @@ cs0164.cs
 cs0186.cs
 cs0187-1.cs
 cs0187-2.cs
+cs0208-4.cs
 cs0229.cs
 cs0249.cs
 cs0266-2.cs
index 95df21d542b39c236f3dad73801f40efaba9c7ff..c7cd31c07d50b9b56c70efa6a0a62e1bbf699b9e 100644 (file)
@@ -19,7 +19,6 @@ cs0156-2.cs
 cs0157-5.cs NO ERROR
 cs0192-2.cs
 cs0201.cs
-cs0208-3.cs
 cs0229.cs NO ERROR
 cs0229-2.cs
 cs0245.cs
@@ -48,6 +47,7 @@ cs0657-17.cs NO ERROR
 cs1501-5.cs
 cs1513.cs
 cs1518.cs
+cs1521-2.cs # Probably not a real regression.  The actual error message is correct
 cs1525.cs
 cs1528.cs
 cs1535.cs
index c9fecf1468a6db1889d10dc365fed8fb5f2a80cf..005cd0b552838be9d285c023fc55342f36b9767e 100644 (file)
@@ -1,3 +1,16 @@
+2005-04-01  Raja R Harinath  <rharinath@novell.com>
+
+       Fix #74232 and cs0208-3.cs.
+       * expression.cs (ComposedCast.DoResolveAsTypeStep): Add CS0208 check.
+       * typemanager.cs (IsUnmanagedType): Don't allow 'object' as an
+       unmanaged type.  Don't use FieldBuilders when 't' is a
+       TypeBuilder.  Use ModFlags and MemberType fields.
+       * class.cs (MemberBase.member_type): Rename from MemberType.
+       (MemberBase.MemberType): New property.  Determines member_type on
+       demand.
+       (MemberBase.DoDefine): Don't initialize MemberType here.
+       (FieldMember.Define): Likewise.
+
 2005-04-01  Marek Safar  <marek.safar@seznam.cz>
 
        Fix #74241
index 845d103b1013cfb3aea43775606592c68014d990..c8cfc4abc0744b2eb33466066de48693660c5548 100644 (file)
@@ -4870,7 +4870,21 @@ namespace Mono.CSharp {
                //
                // The type of this property / indexer / event
                //
-               public Type MemberType;
+               Type member_type;
+               public Type MemberType {
+                       get {
+                               if (member_type == null && Type != null) {
+                                       EmitContext ec = Parent.EmitContext;
+                                       bool old_unsafe = ec.InUnsafe;
+                                       ec.InUnsafe = InUnsafe;
+                                       Type = Type.ResolveAsTypeTerminal (ec, false);
+                                       ec.InUnsafe = old_unsafe;
+
+                                       member_type = Type == null ? null : Type.Type;
+                               }
+                               return member_type;
+                       }
+               }
 
                //
                // Whether this is an interface member.
@@ -4986,17 +5000,9 @@ namespace Mono.CSharp {
                                flags = Modifiers.MethodAttr (ModFlags);
                        }
 
-                       // Lookup Type, verify validity
-                       bool old_unsafe = ec.InUnsafe;
-                       ec.InUnsafe = InUnsafe;
-                       Type = Type.ResolveAsTypeTerminal (ec, false);
-                       ec.InUnsafe = old_unsafe;
-
-                       if (Type == null)
+                       if (MemberType == null)
                                return false;
 
-                       MemberType = Type.Type;
-
                        if ((Parent.ModFlags & Modifiers.SEALED) != 0){
                                if ((ModFlags & (Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0){
                                        Report.Error (549, Location, "Virtual method can not be contained in sealed class");
@@ -5306,16 +5312,9 @@ namespace Mono.CSharp {
                        if (ec == null)
                                throw new InternalErrorException ("FieldMember.Define called too early");
 
-                       bool old_unsafe = ec.InUnsafe;
-                       ec.InUnsafe = InUnsafe;
-                       TypeExpr texpr = Type.ResolveAsTypeTerminal (ec, false);
-                       if (texpr == null)
+                       if (MemberType == null)
                                return false;
 
-                       MemberType = texpr.ResolveType (ec);
-
-                       ec.InUnsafe = old_unsafe;
-
                        if (MemberType == TypeManager.void_type) {
                                Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
                                return false;
index 4e369dce71f61eb7e4b2921c4c08e941a6c83c30..6035c2f9d739715dd70e71e98bcda770a0144b27 100644 (file)
@@ -8542,6 +8542,11 @@ namespace Mono.CSharp {
                                return null;
                        }
 
+                       if (dim == "*" && !TypeManager.IsUnmanagedType (ltype)) {
+                               Report.Error (208, loc, "Cannot declare a pointer to a managed type ('{0}')", ltype);
+                               return null;
+                       }
+
                        type = TypeManager.GetConstructedType (ltype, dim);
                        if (type == null) {
                                throw new InternalErrorException ("Couldn't create computed type " + ltype + dim);
index c8b439ad358926551810dd1248765a04f4a31e15..e7c7800e8519a90931ea53890f1a9324d52c09a8 100644 (file)
@@ -1521,7 +1521,7 @@ public class TypeManager {
        //
        public static bool IsUnmanagedType (Type t)
        {
-               if (IsBuiltinType (t) && t != TypeManager.string_type)
+               if (IsBuiltinType (t) && t != TypeManager.object_type && t != TypeManager.string_type)
                        return true;
 
                if (IsEnumType (t))
@@ -1530,33 +1530,33 @@ public class TypeManager {
                if (t.IsPointer)
                        return true;
 
-               if (IsValueType (t)){
-                       if (t is TypeBuilder){
-                               TypeContainer tc = LookupTypeContainer (t);
-
-                               if (tc.Fields != null){
-                                       foreach (Field f in tc.Fields){
-                                               if (f.FieldBuilder.IsStatic)
-                                                       continue;
-                                               if (!IsUnmanagedType (f.FieldBuilder.FieldType))
-                                                       return false;
-                                       }
-                               } else
-                                       return true;
-                       } else {
-                               FieldInfo [] fields = t.GetFields ();
+               if (!IsValueType (t))
+                       return false;
 
-                               foreach (FieldInfo f in fields){
-                                       if (f.IsStatic)
-                                               continue;
-                                       if (!IsUnmanagedType (f.FieldType))
-                                               return false;
-                               }
+               if (t is TypeBuilder){
+                       TypeContainer tc = LookupTypeContainer (t);
+                       
+                       if (tc.Fields == null)
+                               return true;
+                       foreach (Field f in tc.Fields){
+                               // Avoid using f.FieldBuilder: f.Define () may not yet have been invoked.
+                               if ((f.ModFlags & Modifiers.STATIC) != 0)
+                                       continue;
+                               if (!IsUnmanagedType (f.MemberType))
+                                       return false;
                        }
                        return true;
                }
-
-               return false;
+               
+               FieldInfo [] fields = t.GetFields ();
+               
+               foreach (FieldInfo f in fields){
+                       if (f.IsStatic)
+                               continue;
+                       if (!IsUnmanagedType (f.FieldType))
+                               return false;
+               }
+               return true;
        }
                
        public static bool IsValueType (Type t)