2004-12-01 Marek Safar <marek.safar@seznam.cz>
authorMarek Safar <marek.safar@gmail.com>
Thu, 2 Dec 2004 17:02:13 +0000 (17:02 -0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 2 Dec 2004 17:02:13 +0000 (17:02 -0000)
Fix bug #68790
* ecore.cs: CheckMarshallByRefAccess new virtual method for testing
MarshallByReference members access.

* expression.cs: Use CheckMarshallByRefAccess;
Better error CS0197 message.

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

mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/report.cs

index 55be1ac26d75ea7b125451e78ee181db6d8169b9..8d548cec79d4c33fe5aeddb2e1fa57b94cf651bc 100755 (executable)
@@ -192,6 +192,9 @@ namespace Mono.CSharp {
                        Report.Warning (code, loc, format, args);
                }
 
+               // Not nice but we have broken hierarchy
+               public virtual void CheckMarshallByRefAccess (Type container) {}
+
                /// <summary>
                /// Tests presence of ObsoleteAttribute and report proper error
                /// </summary>
@@ -2730,6 +2733,14 @@ namespace Mono.CSharp {
                        return null;
                }
 
+               public override void CheckMarshallByRefAccess (Type container)
+               {
+                       if (!IsStatic && Type.IsValueType && !container.IsSubclassOf (TypeManager.mbr_type) && DeclaringType.IsSubclassOf (TypeManager.mbr_type)) {
+                               Report.SymbolRelatedToPreviousError (DeclaringType);
+                               Report.Error (1690, loc, "Cannot call '{0}' method, property, or indexer because it is a value type member of a marshal-by-reference class", Name);
+                       }
+               }
+
                public bool VerifyFixed (bool is_expression)
                {
                        IVariable variable = instance_expr as IVariable;
@@ -3100,6 +3111,8 @@ namespace Mono.CSharp {
                                instance_expr = instance_expr.DoResolve (ec);
                                if (instance_expr == null)
                                        return false;
+
+                               instance_expr.CheckMarshallByRefAccess (ec.ContainerType);
                        }
 
                        if (must_do_cs1540_check && (instance_expr != null)) {
index b82b41e84968215dcc8ff2cc75a0060e25be6f18..1c0f3763b6d6d0ea45aa1e938edb746adc0901f9 100755 (executable)
@@ -4147,8 +4147,9 @@ namespace Mono.CSharp {
 
                                        if (instance.GetType () != typeof (This)){
                                                if (fe.InstanceExpression.Type.IsSubclassOf (TypeManager.mbr_type)){
-                                                       Report.Error (197, loc,
-                                                                     "Can not pass a type that derives from MarshalByRefObject with out or ref");
+                                                       Report.SymbolRelatedToPreviousError (fe.InstanceExpression.Type);
+                                                       Report.Error (197, loc, "Cannot pass '{0}' as ref or out or take its address because it is a member of a marshal-by-reference class",
+                                                               fe.Name);
                                                        return false;
                                                }
                                        }
@@ -5152,6 +5153,9 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (mg.InstanceExpression != null)
+                               mg.InstanceExpression.CheckMarshallByRefAccess (ec.ContainerType);
+
                        eclass = ExprClass.Value;
                        return this;
                }
@@ -8177,6 +8181,8 @@ namespace Mono.CSharp {
                                UnsafeError (loc);
                                return null;
                        }
+
+                       instance_expr.CheckMarshallByRefAccess (ec.ContainerType);
                        
                        eclass = ExprClass.IndexerAccess;
                        return this;
@@ -8247,6 +8253,8 @@ namespace Mono.CSharp {
                                }
                        }
                        
+                       instance_expr.CheckMarshallByRefAccess (ec.ContainerType);
+
                        eclass = ExprClass.IndexerAccess;
                        return this;
                }
index 845d95d9e138e67b10d0e27b2e1816b7568be846..7749d6f5866bf3e36769ca90734e1277a3c086f2 100644 (file)
@@ -94,7 +94,7 @@ namespace Mono.CSharp {
                                Console.Error.WriteLine (msg.ToString ());
 
                                foreach (string s in extra_information) 
-                                       Console.Error.WriteLine (s);
+                                       Console.Error.WriteLine (s + MessageType + ")");
 
                                extra_information.Clear ();