[svn] r6160: nemerle/trunk/ncc: parsing/MainParser.n testsuite/positive/gen-special.n typing/TyVarEnv.n

nazgul svnadmin at nemerle.org
Sun Mar 19 15:20:13 CET 2006


Log:
Add special syntax for enum in generic constraint

Author: nazgul
Date: Sun Mar 19 15:20:11 2006
New Revision: 6160

Modified:
   nemerle/trunk/ncc/parsing/MainParser.n
   nemerle/trunk/ncc/testsuite/positive/gen-special.n
   nemerle/trunk/ncc/typing/TyVarEnv.n

Modified: nemerle/trunk/ncc/parsing/MainParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/MainParser.n	(original)
+++ nemerle/trunk/ncc/parsing/MainParser.n	Sun Mar 19 15:20:11 2006
@@ -1249,6 +1249,7 @@
               expect_operator (":");
               def types = comma_separated_list (fun () {
                 match (peek_token ()) {
+                  | Token.Keyword ("enum" as key) as tok                  
                   | Token.Keyword ("class" as key) as tok
                   | Token.Keyword ("struct" as key) as tok =>
                     shift ();

Modified: nemerle/trunk/ncc/testsuite/positive/gen-special.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/gen-special.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/gen-special.n	Sun Mar 19 15:20:11 2006
@@ -24,6 +24,43 @@
   }
 }
 
+namespace EnumSpecifier {
+       enum LicenseAccessLevelType
+       {
+               | Growing
+               | Supplemental
+       }
+
+       [Record]
+       class LicenseManager['t] where 't : enum
+       {
+               _current : 't;
+               _licenseAccessLevelType : LicenseAccessLevelType = LicenseAccessLevelType.Growing;
+
+               public Validate(required : 't) : bool
+               {
+                       def curInt = (_current:System.IConvertible).ToInt32(null);
+                       def reqInt = (required:System.IConvertible).ToInt32(null);
+
+                       match(_licenseAccessLevelType)
+                       {
+                          | Growing =>
+                               (curInt < reqInt);
+                          | Supplemental =>
+                               (curInt & reqInt) != curInt;
+                          | _ =>
+                               throw System.NotImplementedException();
+                       }
+               }
+       }
+       class E { 
+         public static Run () : void { 
+           def l = LicenseManager (LicenseAccessLevelType.Growing, LicenseAccessLevelType.Growing);  
+           _ = l.Validate (LicenseAccessLevelType.Growing);
+         }  
+       }     
+}  
+
 class Foo {
 }
 
@@ -48,6 +85,7 @@
 assert (C().foo (2) == 0);
 assert (C().foo (Foo()) != null);
 assert (D().foo (Foo()) != null);
+EnumSpecifier.E.Run ();
 
 
 /*

Modified: nemerle/trunk/ncc/typing/TyVarEnv.n
==============================================================================
--- nemerle/trunk/ncc/typing/TyVarEnv.n	(original)
+++ nemerle/trunk/ncc/typing/TyVarEnv.n	Sun Mar 19 15:20:11 2006
@@ -403,13 +403,13 @@
               | <[ @class ]> => special |= GenericParameterAttributes.ReferenceTypeConstraint;
               | <[ @struct ]> => special |= GenericParameterAttributes.NotNullableValueTypeConstraint;
               | <[ @new ]> => special |= GenericParameterAttributes.DefaultConstructorConstraint;
-              | _ =>
-                def ty = tenv.MonoBind (env, curtc, c.ty, check_parms);
+              | <[ @enum ]> with cty = <[ System.Enum ]>
+              | cty =>
+                def ty = tenv.MonoBind (env, curtc, cty, check_parms);
                 if (subtype.Contains (ty))
                   Message.Error ($"constraint `$ty' is already declared for $tv");
                 else
                   subtype = ty :: subtype;
-                
             }
             constraints [tv.id] = (special, subtype);
             



More information about the svn mailing list