[svn] r7637: nemerle/trunk: macros/compiler.n macros/core.n ncc/hierarchy/ClassMembers.n ncc/hierarchy/Cus...

malekith svnadmin at nemerle.org
Mon Apr 30 17:19:00 CEST 2007


Log:
Disallow matching variant options against values of non-variant types. Fix the sources, not to do that (several possible bugs fixed).

Author: malekith
Date: Mon Apr 30 17:18:55 2007
New Revision: 7637

Modified:
   nemerle/trunk/macros/compiler.n
   nemerle/trunk/macros/core.n
   nemerle/trunk/ncc/hierarchy/ClassMembers.n
   nemerle/trunk/ncc/hierarchy/CustomAttribute.n
   nemerle/trunk/ncc/hierarchy/TypeInfo.n
   nemerle/trunk/ncc/parsing/Lexer.n
   nemerle/trunk/ncc/parsing/PreParser.n
   nemerle/trunk/ncc/typing/Subst.n
   nemerle/trunk/ncc/typing/TyVarEnv.n
   nemerle/trunk/ncc/typing/Typer-OverloadSelection.n
   nemerle/trunk/ncc/typing/Typer-PatternTyper.n
   nemerle/trunk/ncc/typing/Typer.n
   nemerle/trunk/snippets/ants-icfp2004/simulator/environment.n
   nemerle/trunk/snippets/designpatt/proxy-m.n

Modified: nemerle/trunk/macros/compiler.n
==============================================================================
--- nemerle/trunk/macros/compiler.n	(original)
+++ nemerle/trunk/macros/compiler.n	Mon Apr 30 17:18:55 2007
@@ -232,7 +232,7 @@
 
         //def s = field.Name;
 
-        match (ty)
+        match (ty.DeepFix ())
         {
           // Ignore property of some types. It prevent unproductive recursion.
           | Class (t is TypeBuilder, []) when equalsAny(t, ignoreTypeList) 
@@ -241,10 +241,10 @@
           
           // Skip IMacro members.
           | Class (t, []) when t.Equals(iMacroTyInfo)
-          | Class (_, [MType.Class(t, [])]) when t.Equals(iMacroTyInfo) => ()
+          | Class (_, [TyVar where (FixedValue = MType.Class(t, []))]) when t.Equals(iMacroTyInfo) => ()
 
           // Process 'collection[Location]' fields (make relocation code for it).
-          | Class (tc, [MType.Class(ti, [])]) when ti.Equals(locationTyInfo) => 
+          | Class (tc, [TyVar where (FixedValue = MType.Class(ti, []))]) when ti.Equals(locationTyInfo) => 
             if (isMutable (field))
               if (tc.Equals(listTyInfo) || tc.Equals(stackTyInfo))
                 exprs ::= <[ 
@@ -266,7 +266,7 @@
           // Below reference fields processed...
 
           // 1. Is optional field of reference type defined in this project. 
-          | Class (tc, [MType.Class(t is TypeBuilder, _)]) when tc.Equals(optinTyInfo) =>
+          | Class (tc, [TyVar where (FixedValue = MType.Class(t is TypeBuilder, _))]) when tc.Equals(optinTyInfo) =>
             exprs ::= if (t.IsInterface)
               <[
                 match (this.$(n : name))
@@ -289,7 +289,7 @@
               ]>;
 
           // 2. Is collection of reference type defined in this project.
-          | Class (_, [MType.Class(t is TypeBuilder, _)]) when isStepInto (t) =>
+          | Class (_, [TyVar where (FixedValue = MType.Class(t is TypeBuilder, _))]) when isStepInto (t) =>
             exprs ::= if (t.IsInterface)
               <[
                 def x = this.$(n : name);

Modified: nemerle/trunk/macros/core.n
==============================================================================
--- nemerle/trunk/macros/core.n	(original)
+++ nemerle/trunk/macros/core.n	Mon Apr 30 17:18:55 2007
@@ -415,7 +415,7 @@
       
       def choosen = List.Exists (all, fun (mem : IMember) {
         | meth is IMethod when !meth.IsStatic && meth.GetParameters ().IsEmpty =>
-          match (meth.ReturnType) {
+          match (meth.ReturnType.Fix ()) {
             // FIXME: do additional conservative checks              
             | MType.Class (tc, _) when
               !tc.LookupMember ("MoveNext").IsEmpty &&

Modified: nemerle/trunk/ncc/hierarchy/ClassMembers.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/ClassMembers.n	(original)
+++ nemerle/trunk/ncc/hierarchy/ClassMembers.n	Mon Apr 30 17:18:55 2007
@@ -1086,7 +1086,7 @@
   // this method check the specification from CLI ECMA-335 II 9.7
   internal static check_variance_valid (t : TyVar, enforced_variance_sign : int) : bool
   {
-    match (t) {
+    match (t.Fix ()) {
       | MType.Class (_, []) => true // is always valid
       | MType.TyVarRef (tr) => 
         if (enforced_variance_sign > 0)

Modified: nemerle/trunk/ncc/hierarchy/CustomAttribute.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/CustomAttribute.n	(original)
+++ nemerle/trunk/ncc/hierarchy/CustomAttribute.n	Mon Apr 30 17:18:55 2007
@@ -63,7 +63,7 @@
           (lit.AsObject (InternalType), lit.GetInternalType (InternalType))
 
         | <[ typeof ($t) ]> when ti != null =>
-          match (ti.BindType (t)) {
+          match (ti.BindType (t).Fix ()) {
             | MType.Class (tc, args) => 
               def is_free (a) { !(a is MType) }
               if (args.Exists (is_free)) {

Modified: nemerle/trunk/ncc/hierarchy/TypeInfo.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/TypeInfo.n	(original)
+++ nemerle/trunk/ncc/hierarchy/TypeInfo.n	Mon Apr 30 17:18:55 2007
@@ -503,7 +503,7 @@
       | Property when (mem :> IProperty).IsIndexer
       | Constructor | Method =>
         // FIXME: this won't work for generic methods
-        match (GetMemType ().TypeOfMember (mem)) {
+        match (GetMemType ().TypeOfMember (mem).Fix ()) {
           | MType.Fun (from, _) => Some (from.Fix ())
           | _ => None ()
         }

Modified: nemerle/trunk/ncc/parsing/Lexer.n
==============================================================================
--- nemerle/trunk/ncc/parsing/Lexer.n	(original)
+++ nemerle/trunk/ncc/parsing/Lexer.n	Mon Apr 30 17:18:55 2007
@@ -136,7 +136,8 @@
     }
   }
 
-  public GetEnumerator () : System.Collections.IEnumerator {
+  public GetEnumerator () : System.Collections.Generic.IEnumerator [Token]
+  {
     match (this) {
       | RoundGroup (child) | BracesGroup (child) | SquareGroup (child)
       | QuoteGroup (child) | LooseGroup (child)  | Namespace (_, child) =>
@@ -206,13 +207,14 @@
 }
 
 [DebuggerNonUserCode]
-public class TokenEnumerator : System.Collections.IEnumerator {
+public class TokenEnumerator : System.Collections.Generic.IEnumerator [Token]
+{
   mutable current : Token;
   mutable next : Token;  
 
   public this (begin : Token) { next = begin; }
 
-  public Current : object { get { current } }
+  public Current : Token { get { current } }
 
   public MoveNext () : bool {
     if (next != null) {
@@ -224,6 +226,8 @@
   }
 
   public Reset () : void {  }
+
+  public Dispose () : void {  }
 }
 
 public class Region

Modified: nemerle/trunk/ncc/parsing/PreParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/PreParser.n	(original)
+++ nemerle/trunk/ncc/parsing/PreParser.n	Mon Apr 30 17:18:55 2007
@@ -154,7 +154,7 @@
         }
       def builder = System.Text.StringBuilder (open);
       when (elements != null)
-        foreach (e is Token in elements) 
+        foreach (e in elements) 
           _ = builder.Append (Dump (e, ident + "  ")).Append (sepstr);
       builder.Append (close).ToString ()
     }

Modified: nemerle/trunk/ncc/typing/Subst.n
==============================================================================
--- nemerle/trunk/ncc/typing/Subst.n	(original)
+++ nemerle/trunk/ncc/typing/Subst.n	Mon Apr 30 17:18:55 2007
@@ -167,20 +167,25 @@
           // we have f->t in this
           map.Fold (map, fun (f, t, map) {
             def replace_targets (from, to) {
-              other.map.Fold (map, fun (_) {
-                | (x, MType.TyVarRef (from'), map) when from'.Id == from.Id =>
+              other.map.Fold (map, fun (x, ty, map) {
+                match (ty.Fix ()) {
+                  | MType.TyVarRef (from') when from'.Id == from.Id =>
                   map.Replace (x, to)
-                | (_, _, map) => map
+                  | _ => map
+                }
               })
             }
 
             match (other.map.Find (f)) {
               // there is f->of in other
-              | Some (MType.TyVarRef (of)) =>
+              | Some (tv) =>
+                match (tv.Fix ()) {
+                  | MType.TyVarRef (of) =>
                 replace_targets (of, t).Replace (of.Id, t)
-              | None => map
               | x => Util.ice ($"$x")
             }
+              | None => map
+            }
           })
       }
     }

Modified: nemerle/trunk/ncc/typing/TyVarEnv.n
==============================================================================
--- nemerle/trunk/ncc/typing/TyVarEnv.n	(original)
+++ nemerle/trunk/ncc/typing/TyVarEnv.n	Mon Apr 30 17:18:55 2007
@@ -147,7 +147,7 @@
                         .Apply (ti.DeclaringType.GetMemType ()).Fix ())
                   else find_nesting (nesting.DeclaringType)
                 }
-                match (find_nesting (curtc)) {
+                match (find_nesting (curtc).Fix ()) {
                   | null =>
                     ReportError (messenger,
                                  $ "cannot determine nested type parameters "

Modified: nemerle/trunk/ncc/typing/Typer-OverloadSelection.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer-OverloadSelection.n	(original)
+++ nemerle/trunk/ncc/typing/Typer-OverloadSelection.n	Mon Apr 30 17:18:55 2007
@@ -282,7 +282,7 @@
         | _ =>
           def pairs =
             List.RevMap (parms, fun (from, meth) {
-                match (from.TypeOfMethodWithTyparms (meth) [0]) {
+                match (from.TypeOfMethodWithTyparms (meth) [0].Fix ()) {
                   | MType.Fun (src, _) => (src, (from, meth))
                   | _ => assert (false)
                 }

Modified: nemerle/trunk/ncc/typing/Typer-PatternTyper.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer-PatternTyper.n	(original)
+++ nemerle/trunk/ncc/typing/Typer-PatternTyper.n	Mon Apr 30 17:18:55 2007
@@ -474,6 +474,12 @@
                       def option_type = ti.GetFreshType ();
                       // Message.Debug ($ "$matched_value_type Provide $option_type");
                       if (matched_value_type.Provide (option_type)) {
+                        def parent = ti.SuperClass ().Value.GetFreshType ();
+                        when (! matched_value_type.Require (parent))
+                          ReportError (messenger,
+                                       $ "the matched value type "
+                                         "$matched_value_type was expected "
+                                         "to be subtype of $parent");
                         def inpat = TypePattern (option_type, pattern);
                         Pattern.Application (ti, inpat)
                       } else {

Modified: nemerle/trunk/ncc/typing/Typer.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer.n	(original)
+++ nemerle/trunk/ncc/typing/Typer.n	Mon Apr 30 17:18:55 2007
@@ -1404,7 +1404,8 @@
         | PT.PExpr.Typeof (t) =>
           _ = Expect (expected, InternalType.Type, "typeof result");
           def ty = BindType (t);
-          match (ty) {
+          if (ty.IsFixed)
+            match (ty :> MType) {
             | MType.Tuple (args) with tc = InternalType.GetTupleType (args.Length).TyCon
             | MType.Class (tc, args) =>
               def is_free (a) { !(a is MType) }
@@ -1416,6 +1417,10 @@
               else TExpr.TypeOf (ty)
             | _ => TExpr.TypeOf (ty)
           }          
+          else {
+            Message.Error ("typeof(_) doesn't make much sense");
+            TExpr.TypeOf (InternalType.Object)
+          }
 
         | <[ _ :> $_ ]>
         | <[ _ : $_ ]>
@@ -2118,7 +2123,7 @@
     {
       if (pt_from == null) {}
       else
-        match (current_type.BindType (pt_from)) {
+        match (current_type.BindType (pt_from).Fix ()) {
           | MType.Class (tc, args) =>
             if (tc.Equals (from.tycon.DeclaringType)) {
               _ = args.FoldLeft (from.args, fun (pa, fas) {
@@ -2215,7 +2220,7 @@
                             additional_sig_types : list [MType] = null) : MType.Class
     {
       if (pt_from != null) {
-        match (current_type.BindType (pt_from)) {
+        match (current_type.BindType (pt_from).Fix ()) {
           | MType.Class as c => c
           | _ =>
             ReportError (messenger, $ "$pt_from is not a class type");
@@ -2235,11 +2240,13 @@
           foreach (tv in declaring.Typarms)
             type_tyvars [tv.Id] = tv;
 
-          def clear_ht (_) {
+          def clear_ht (t) {
+            match (t.Fix ()) {
             | MType.TyVarRef (tv) when type_tyvars.ContainsKey (tv.Id) =>
               type_tyvars [tv.Id] = null;
             | _ => {}
           }
+          }
           
           symbol.GetMemType ().Iter (clear_ht);
           
@@ -2640,7 +2647,7 @@
             def was_error =
               try {
                 solver.PushState ();
-                ! (current_type.BindType (expr) is MType.Class (_, _ :: _)) ||
+                ! (current_type.BindType (expr).Fix () is MType.Class (_, _ :: _)) ||
                 messenger.LocalError
               } finally {
                 solver.PopState ()
@@ -2684,7 +2691,7 @@
               }
           }
         else
-          match (current_type.BindType (pt_from)) {
+          match (current_type.BindType (pt_from).Fix ()) {
             | MType.Class (tc, _) =>
               tc.LookupMember (mem_name, for_completion)
             | _ =>

Modified: nemerle/trunk/snippets/ants-icfp2004/simulator/environment.n
==============================================================================
--- nemerle/trunk/snippets/ants-icfp2004/simulator/environment.n	(original)
+++ nemerle/trunk/snippets/ants-icfp2004/simulator/environment.n	Mon Apr 30 17:18:55 2007
@@ -36,7 +36,7 @@
       get
       {
         match (this) {
-          | Color.Red => Color.Black ()
+          | _ is Color.Red => Color.Black ()
           | _ => Color.Red ()
         }
       }

Modified: nemerle/trunk/snippets/designpatt/proxy-m.n
==============================================================================
--- nemerle/trunk/snippets/designpatt/proxy-m.n	(original)
+++ nemerle/trunk/snippets/designpatt/proxy-m.n	Mon Apr 30 17:18:55 2007
@@ -10,7 +10,7 @@
   macro Proxy (t : TypeBuilder, f : FieldBuilder, iface)
   {
     // find out the real type specified as [iface] parameter
-    def interfc = match (Nemerle.Macros.ImplicitCTX().BindType (iface))
+    def interfc = match (Nemerle.Macros.ImplicitCTX().BindType (iface).Fix ())
     {
       | MType.Class (typeinfo, _) when typeinfo.IsInterface => typeinfo
       | _ => Message.FatalError ("expected interface type")



More information about the svn mailing list