[svn] r5934: nemerle/trunk/ncc: hierarchy/TypeBuilder.n
testsuite/negative/tyvars.n
malekith
svnadmin at nemerle.org
Mon Nov 14 23:05:44 CET 2005
Log:
Flag duplicate tyvars (including ones from nesting types) as error. Resolves #536.
Author: malekith
Date: Mon Nov 14 23:05:43 2005
New Revision: 5934
Added:
nemerle/trunk/ncc/testsuite/negative/tyvars.n
Modified:
nemerle/trunk/ncc/hierarchy/TypeBuilder.n
Modified: nemerle/trunk/ncc/hierarchy/TypeBuilder.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/TypeBuilder.n (original)
+++ nemerle/trunk/ncc/hierarchy/TypeBuilder.n Mon Nov 14 23:05:43 2005
@@ -986,7 +986,14 @@
// after we updated parsed tenvs of types with partial parts
// we should copy them to nested types
// we do this using parsetrees, so the fresh StaticVars are used
- unless (this.pt_tydecl.typarms == null)
+ unless (this.pt_tydecl.typarms == null) {
+ def ht = Hashtable ();
+
+ foreach (tv in this.pt_tydecl.typarms.tyvars)
+ if (ht.Contains (tv))
+ Message.Error ($ "duplicate type parameter `$(tv [0])'")
+ else ht [tv] = tv;
+
match (this.pt_tydecl) {
| PT.TopDeclaration.Class (_, decls)
| PT.TopDeclaration.Variant (_, decls) =>
@@ -996,6 +1003,16 @@
else {
def tp1 = this.pt_tydecl.typarms;
def tp2 = x.typarms;
+ foreach (tv in tp2.tyvars)
+ when (ht.Contains (tv)) {
+ Message.Error (x.loc,
+ $ "type parameter `$(tv [0])' has the same "
+ "name as type parameter from the outer "
+ "type `$(this)'");
+ Message.Hint ("type parameters are inherited in nested "
+ "types and can be used without declaring "
+ "them explicitly");
+ }
x.typarms =
PT.Typarms (tp1.tyvars + tp2.tyvars,
tp1.constraints + tp2.constraints)
@@ -1003,6 +1020,7 @@
}
| _ => ()
}
+ }
match (pt_tydecl) {
| PT.TopDeclaration.VariantOption (members) =>
Added: nemerle/trunk/ncc/testsuite/negative/tyvars.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/negative/tyvars.n Mon Nov 14 23:05:43 2005
@@ -0,0 +1,6 @@
+class A [a, a] { } // E: duplicate type parameter `a'
+
+class B [x] {
+ class C [x] { // E: type parameter `x' has the same name as type parameter from the outer type `B'
+ }
+}
More information about the svn
mailing list