2003-04-19 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Sat, 19 Apr 2003 21:18:35 +0000 (21:18 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Sat, 19 Apr 2003 21:18:35 +0000 (21:18 -0000)
* delegate.cs (NewDelegate.Resolve): Test whether an instance
method is being referenced in the method group from a static
context, and report error 120 if so.

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

mcs/mcs/ChangeLog
mcs/mcs/assign.cs
mcs/mcs/delegate.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/statement.cs

index ee08ea5b246d387f7d83f646277ee901d80bf096..2fa9283a97630f999c6584c57d558af2c03cc5ee 100755 (executable)
@@ -1,5 +1,12 @@
 2003-04-19  Miguel de Icaza  <miguel@ximian.com>
 
+       * delegate.cs (NewDelegate.Resolve): Test whether an instance
+       method is being referenced in the method group from a static
+       context, and report error 120 if so.
+
+       * expression.cs, ecore.cs (Error_UnexpectedKind): New name for
+       Error118. 
+
        * typemanager.cs: Add intermediate namespaces (if a namespace A.B
        is created, we create the A namespace).
 
index 167875f7f966372e87d65a145906f7bbbd3adb7e..acbd361fcf777a2c18ae70039c5d03a6e1202979 100755 (executable)
@@ -282,7 +282,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((source.eclass == ExprClass.Type) && (source is TypeExpr)) {
-                               source.Error118 ("variable or value");
+                               source.Error_UnexpectedKind ("variable or value");
                                return null;
                        } else if (source is MethodGroupExpr){
                                ((MethodGroupExpr) source).ReportUsageError ();
index 156700bbbc1e86eddd597262a7a4cb4fd5637ba7..0ac6db64e66df4996801e73acf0cfa26237ef51d 100644 (file)
@@ -564,15 +564,9 @@ namespace Mono.CSharp {
 \r
                public override Expression DoResolve (EmitContext ec)\r
                {\r
-                       if (Arguments == null) {\r
-                               Report.Error (-11, loc,\r
-                                             "Delegate creation expression takes only one argument");\r
-                               return null;\r
-                       }\r
-\r
-                       if (Arguments.Count != 1) {\r
-                               Report.Error (-11, loc,\r
-                                             "Delegate creation expression takes only one argument");\r
+                       if (Arguments == null || Arguments.Count != 1) {\r
+                               Report.Error (149, loc,\r
+                                             "Method name expected");\r
                                return null;\r
                        }\r
 \r
@@ -646,10 +640,16 @@ namespace Mono.CSharp {
                                if (mg.InstanceExpression != null)\r
                                        delegate_instance_expr = mg.InstanceExpression.Resolve (ec);\r
                                else {\r
-                                       if (!ec.IsStatic)\r
-                                               delegate_instance_expr = ec.This;\r
-                                       else\r
+                                       if (ec.IsStatic){\r
+                                               if (!delegate_method.IsStatic){\r
+                                                       Report.Error (120, loc,\r
+                                                                     "An object reference is required for the non-static method " +\r
+                                                                     delegate_method.Name);\r
+                                                       return null;\r
+                                               }\r
                                                delegate_instance_expr = null;\r
+                                       } else\r
+                                               delegate_instance_expr = ec.This;\r
                                }\r
 \r
                                if (delegate_instance_expr != null)\r
@@ -663,8 +663,7 @@ namespace Mono.CSharp {
                        Type e_type = e.Type;\r
 \r
                        if (!TypeManager.IsDelegateType (e_type)) {\r
-                               Report.Error (-12, loc, "Cannot create a delegate from something " +\r
-                                             "not a delegate or a method.");\r
+                               e.Error_UnexpectedKind ("method");\r
                                return null;\r
                        }\r
 \r
index f58b6c08d62685c973cb3d3d176e55d98f1c3c1d..46a3c677a1a5e01ad9ecd576180fd6d508ca82b8 100755 (executable)
@@ -336,7 +336,7 @@ namespace Mono.CSharp {
 
                        if ((e is TypeExpr) || (e is ComposedCast)) {
                                if ((flags & ResolveFlags.Type) == 0) {
-                                       e.Error118 (flags);
+                                       e.Error_UnexpectedKind (flags);
                                        return null;
                                }
 
@@ -346,7 +346,7 @@ namespace Mono.CSharp {
                        switch (e.eclass) {
                        case ExprClass.Type:
                                if ((flags & ResolveFlags.VariableOrValue) == 0) {
-                                       e.Error118 (flags);
+                                       e.Error_UnexpectedKind (flags);
                                        return null;
                                }
                                break;
@@ -369,7 +369,7 @@ namespace Mono.CSharp {
                                        FieldInfo fi = ((FieldExpr) e).FieldInfo;
                                        
                                        Console.WriteLine ("{0} and {1}", fi.DeclaringType, fi.Name);
-                                       e.Error118 (flags);
+                                       e.Error_UnexpectedKind (flags);
                                        return null;
                                }
                                break;
@@ -2472,7 +2472,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Reports that we were expecting `expr' to be of class `expected'
                /// </summary>
-               public void Error118 (string expected)
+               public void Error_UnexpectedKind (string expected)
                {
                        string kind = "Unknown";
                        
@@ -2482,7 +2482,7 @@ namespace Mono.CSharp {
                               "' where a `" + expected + "' was expected");
                }
 
-               public void Error118 (ResolveFlags flags)
+               public void Error_UnexpectedKind (ResolveFlags flags)
                {
                        ArrayList valid = new ArrayList (10);
 
index 0e03285744a3e072f294764c7213a0f264396407..b0277b05e9c7bacc81db362f2c90cc9328bf6e0e 100755 (executable)
@@ -808,7 +808,7 @@ namespace Mono.CSharp {
 
                                return null;
                        } else {
-                               expr.Error118 ("variable, indexer or property access");
+                               expr.Error_UnexpectedKind ("variable, indexer or property access");
                                return null;
                        }
 
@@ -4486,7 +4486,7 @@ namespace Mono.CSharp {
                        }
 
                        if (!(expr is MethodGroupExpr)){
-                               expr.Error118 (ResolveFlags.MethodGroup);
+                               expr.Error_UnexpectedKind (ResolveFlags.MethodGroup);
                                return null;
                        }
 
@@ -4905,7 +4905,7 @@ namespace Mono.CSharp {
                        
                        if (! (ml is MethodGroupExpr)){
                                if (!is_struct){
-                                       ml.Error118 ("method group");
+                                       ml.Error_UnexpectedKind ("method group");
                                        return null;
                                }
                        }
@@ -5373,7 +5373,7 @@ namespace Mono.CSharp {
                                                   AllBindingFlags, loc);
                                
                                if (!(ml is MethodGroupExpr)) {
-                                       ml.Error118 ("method group");
+                                       ml.Error_UnexpectedKind ("method group");
                                        return null;
                                }
                                
@@ -6538,7 +6538,7 @@ namespace Mono.CSharp {
                        // As long as the type is valid
                        if (!(eclass == ExprClass.Variable || eclass == ExprClass.PropertyAccess ||
                              eclass == ExprClass.Value)) {
-                               ea.Expr.Error118 ("variable or value");
+                               ea.Expr.Error_UnexpectedKind ("variable or value");
                                return null;
                        }
 #endif
index e394863e0baae81bba5f1db557d50006031f1d9b..32e3e653389ef2edf2d9cd925b848c372eb12350 100755 (executable)
@@ -882,7 +882,7 @@ namespace Mono.CSharp {
 
                                if (!(eclass == ExprClass.Variable || eclass == ExprClass.PropertyAccess ||
                                      eclass == ExprClass.Value || eclass == ExprClass.IndexerAccess)) {
-                                       expr.Error118 ("value, variable, property or indexer access ");
+                                       expr.Error_UnexpectedKind ("value, variable, property or indexer access ");
                                        return false;
                                }