2006-08-12 Marek Safar <marek.safar@seznam.cz>
authorMarek Safar <marek.safar@gmail.com>
Sat, 12 Aug 2006 18:50:43 +0000 (18:50 -0000)
committerMarek Safar <marek.safar@gmail.com>
Sat, 12 Aug 2006 18:50:43 +0000 (18:50 -0000)
* cs-parser.jay: Check whether a constraint clause has already been
specified for type parameter.
* generic.cs (Constraints): Exposed location.

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

mcs/errors/gcs0409.cs [new file with mode: 0644]
mcs/gmcs/ChangeLog
mcs/gmcs/cs-parser.jay
mcs/gmcs/generic.cs

diff --git a/mcs/errors/gcs0409.cs b/mcs/errors/gcs0409.cs
new file mode 100644 (file)
index 0000000..f402657
--- /dev/null
@@ -0,0 +1,6 @@
+// gcs0409.cs: A constraint clause has already been specified for type parameter `U'\r
+// Line: 7\r
+\r
+class C<T, U> where U: class, new() where U: new()\r
+{\r
+}\r
index 3b2abd32176b088040e4c5809432b4fcdccf5c8a..273c9c16e2fe52385de9b897add2d5df35d8246e 100644 (file)
@@ -1,3 +1,9 @@
+2006-08-12  Marek Safar  <marek.safar@seznam.cz>
+
+       * cs-parser.jay: Check whether a constraint clause has already been
+       specified for type parameter.
+       * generic.cs (Constraints): Exposed location.
+
 2006-08-12  Marek Safar  <marek.safar@seznam.cz>
 
        * class.cs (Method.Define): Issue a warning when generic method looks like
index 65912a097f6c37ee61aa279c74c6b9faee4aa493..c97fa6e1562f65cf39c4f499bb84dc1d6c289621 100644 (file)
@@ -3926,8 +3926,16 @@ type_parameter_constraints_clauses
          }
        | type_parameter_constraints_clauses type_parameter_constraints_clause {
                ArrayList constraints = (ArrayList) $1;
+               Constraints new_constraint = (Constraints)$2;
 
-               constraints.Add ($2);
+               foreach (Constraints c in constraints) {
+                       if (new_constraint.TypeParameter == c.TypeParameter) {
+                               Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
+                                       new_constraint.TypeParameter);
+                       }
+               }
+
+               constraints.Add (new_constraint);
                $$ = constraints;
          }
        ; 
index 7ce02aa2785c792c3c916c088ba067be929cdff8..53bee98fb90a2055375adaad92cb4ba851f69756 100644 (file)
@@ -504,6 +504,12 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               public Location Location {
+                       get {
+                               return loc;
+                       }
+               }
+
                /// <summary>
                ///   This is used when we're implementing a generic interface method.
                ///   Each method type parameter in implementing method must have the same