Browse Source

2008-09-19 Marek Safar <[email protected]>

	* cs-parser.jay, expression.cs: Fixed few expression crashes.


svn path=/trunk/mcs/; revision=113518
Marek Safar 17 years ago
parent
commit
1ca80004fc
3 changed files with 44 additions and 9 deletions
  1. 4 0
      mcs/mcs/ChangeLog
  2. 3 2
      mcs/mcs/cs-parser.jay
  3. 37 7
      mcs/mcs/expression.cs

+ 4 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,7 @@
+2008-09-19  Marek Safar  <[email protected]>
+
+	* cs-parser.jay, expression.cs: Fixed few expression crashes.
+	
 2008-09-19  Marek Safar  <[email protected]>
 
 	* cs-tokenizer.cs: Don't break on extra partial modifier.

+ 3 - 2
mcs/mcs/cs-parser.jay

@@ -4474,8 +4474,9 @@ statement_expression
 		if (s == null) {
 			expr.Error_InvalidExpressionStatement ();
 			$$ = null;
-		} 
-		$$ = new StatementExpression (s);
+		} else {
+			$$ = new StatementExpression (s);
+		}
 	  }
 	| error
 	  {

+ 37 - 7
mcs/mcs/expression.cs

@@ -7530,14 +7530,13 @@ namespace Mono.CSharp {
 			if (tnew_expr == null)
 				return null;
 
-			Type expr_type = tnew_expr.Type;
-
-			if (expr_type.IsPointer){
-				Error (23, "The `.' operator can not be applied to pointer operands (" +
-				       TypeManager.CSharpName (expr_type) + ")");
+			if (tnew_expr is TypeParameterExpr) {
+				Report.Error (704, loc, "A nested type cannot be specified through a type parameter `{0}'",
+					tnew_expr.GetSignatureForError ());
 				return null;
 			}
 
+			Type expr_type = tnew_expr.Type;
 			Expression member_lookup = MemberLookup (
 				rc.DeclContainer.TypeBuilder, expr_type, expr_type, LookupIdentifier,
 				MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc);
@@ -9289,6 +9288,22 @@ namespace Mono.CSharp {
 			}
 		}
 
+		sealed class AddMemberAccess : MemberAccess
+		{
+			public AddMemberAccess (Expression expr, Location loc)
+				: base (expr, "Add", loc)
+			{
+			}
+
+			protected override void Error_TypeDoesNotContainDefinition (Type type, string name)
+			{
+				if (TypeManager.HasElementType (type))
+					return;
+
+				base.Error_TypeDoesNotContainDefinition (type, name);
+			}
+		}
+
 		public CollectionElementInitializer (Expression argument)
 			: base (null, new ArrayList (1), true)
 		{
@@ -9345,7 +9360,7 @@ namespace Mono.CSharp {
 				Arguments [i] = new ElementInitializerArgument (expr);
 			}
 
-			base.expr = new MemberAccess (ec.CurrentInitializerVariable, "Add", loc);
+			base.expr = new AddMemberAccess (ec.CurrentInitializerVariable, loc);
 
 			return base.DoResolve (ec);
 		}
@@ -9452,7 +9467,17 @@ namespace Mono.CSharp {
 					initializers [i] = e;
 			}
 
-			type = is_collection_initialization ? typeof (CollectionOrObjectInitializers) : typeof (ElementInitializer);
+			if (is_collection_initialization) {
+				if (TypeManager.HasElementType (ec.CurrentInitializerVariable.Type)) {
+					Report.Error (1925, loc, "Cannot initialize object of type `{0}' with a collection initializer",
+						TypeManager.CSharpName (ec.CurrentInitializerVariable.Type));
+				}
+
+				type = typeof (CollectionOrObjectInitializers);
+			} else {
+				type = typeof (ElementInitializer);
+			}
+
 			eclass = ExprClass.Variable;
 			return this;
 		}
@@ -9692,6 +9717,11 @@ namespace Mono.CSharp {
 		{
 			AnonymousTypeClass anonymous_type;
 
+			if (!ec.IsAnonymousMethodAllowed) {
+				Report.Error (836, loc, "Anonymous types cannot be used in this expression");
+				return null;
+			}
+
 			if (parameters == null) {
 				anonymous_type = CreateAnonymousType (EmptyParameters);
 				return new New (new TypeExpression (anonymous_type.TypeBuilder, loc),