[svn] r6223: nemerle/trunk: boot/Nemerle.Compiler.dll boot/Nemerle.Macros.dll boot/Nemerle.dll boot/ncc.ex...

malekith svnadmin at nemerle.org
Thu May 4 22:09:57 CEST 2006


Log:
Implement C# behavior of giving precedence to non-extension methods.

Author: malekith
Date: Thu May  4 22:09:27 2006
New Revision: 6223

Modified:
   nemerle/trunk/boot/Nemerle.Compiler.dll
   nemerle/trunk/boot/Nemerle.Macros.dll
   nemerle/trunk/boot/Nemerle.dll
   nemerle/trunk/boot/ncc.exe
   nemerle/trunk/ncc/external/LibrariesLoader.n
   nemerle/trunk/ncc/hierarchy/BuiltinMethod.n
   nemerle/trunk/ncc/hierarchy/ClassMembers.n
   nemerle/trunk/ncc/hierarchy/ExtensionMethod.n
   nemerle/trunk/ncc/hierarchy/TypeInfo.n
   nemerle/trunk/ncc/testsuite/positive/extension-methods.n
   nemerle/trunk/ncc/typing/Typer-OverloadSelection.n

Modified: nemerle/trunk/boot/Nemerle.Compiler.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/Nemerle.Macros.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/Nemerle.dll
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/boot/ncc.exe
==============================================================================
Binary files. No diff available.

Modified: nemerle/trunk/ncc/external/LibrariesLoader.n
==============================================================================
--- nemerle/trunk/ncc/external/LibrariesLoader.n	(original)
+++ nemerle/trunk/ncc/external/LibrariesLoader.n	Thu May  4 22:09:27 2006
@@ -1904,6 +1904,11 @@
         get { is_var_args }
       }
 
+      public IsExtensionMethod : bool
+      {
+        get { false }
+      }
+    
       public GetMethodBase () : SR.MethodBase
       {
         handle

Modified: nemerle/trunk/ncc/hierarchy/BuiltinMethod.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/BuiltinMethod.n	(original)
+++ nemerle/trunk/ncc/hierarchy/BuiltinMethod.n	Thu May  4 22:09:27 2006
@@ -179,6 +179,11 @@
       set { ignore (value); }
     }
 
+    public virtual IsExtensionMethod : bool
+    {
+      get { false }
+    }
+    
     public virtual Attributes : NemerleAttributes {
       get { 
         NemerleAttributes.Static | 

Modified: nemerle/trunk/ncc/hierarchy/ClassMembers.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/ClassMembers.n	(original)
+++ nemerle/trunk/ncc/hierarchy/ClassMembers.n	Thu May  4 22:09:27 2006
@@ -703,6 +703,11 @@
     get { is_var_args }
   }
 
+  public IsExtensionMethod : bool
+  {
+    get { false }
+  }
+    
   public this (par : TypeBuilder, f : PT.ClassMember.Function)
   {
     this (par, f, false)

Modified: nemerle/trunk/ncc/hierarchy/ExtensionMethod.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/ExtensionMethod.n	(original)
+++ nemerle/trunk/ncc/hierarchy/ExtensionMethod.n	Thu May  4 22:09:27 2006
@@ -94,5 +94,10 @@
     { 
       get { false } 
     }
+
+    public override IsExtensionMethod : bool
+    {
+      get { true }
+    }
   }
 }

Modified: nemerle/trunk/ncc/hierarchy/TypeInfo.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/TypeInfo.n	(original)
+++ nemerle/trunk/ncc/hierarchy/TypeInfo.n	Thu May  4 22:09:27 2006
@@ -120,6 +120,7 @@
   GetConstructorInfo () : System.Reflection.ConstructorInfo;
   IsVarArgs : bool { get; }
   IsFinal : bool { get; }  
+  IsExtensionMethod : bool { get; }
   BuiltinKind : BuiltinMethodKind { get; }
 
   /// Obtains list of parameters of typed method

Modified: nemerle/trunk/ncc/testsuite/positive/extension-methods.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/extension-methods.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/extension-methods.n	Thu May  4 22:09:27 2006
@@ -2,6 +2,43 @@
 #pragma indent
 using System.Console
 using Nemerle.Collections
+using N1
+
+namespace N1
+{
+    public static class E
+    {
+        public static F(this _obj : object, _i : int) : void {  System.Console.WriteLine ("E.F(obj,int)") }
+        public static F(this _obj : object, _s : string) : void { System.Console.WriteLine ("E.F(obj,string)") }
+    }
+}
+
+namespace N2 {
+class Ax { }
+class Bx
+{
+    public F(_i : int) : void { System.Console.WriteLine ("B.F(int)") }
+}
+class Cx
+{
+    public F(_obj : object) : void { System.Console.WriteLine ("C.F(obj)") }
+}
+class X
+{
+ public static xMain () : void {
+   Test (Ax(), Bx(), Cx());
+ }
+ 
+    static Test(a : Ax, b : Bx, c : Cx) : void {
+        a.F(1);             // E.F(object, int)
+        a.F("hello");       // E.F(object, string)
+        b.F(1);             // B.F(int)
+        b.F("hello");       // E.F(object, string)
+        c.F(1);             // C.F(object)
+        c.F("hello");       // C.F(object)
+    }
+}
+}
 
 module Extensions
     public All [T] (this objs : System.Collections.Generic.IEnumerable[T], fn : T -> bool) : bool
@@ -36,6 +73,8 @@
 a.Iter (fun (x) { WriteLine (x) })
 WriteLine ("gppcbs".Map (fun (c:char) { ((c :> int) - 1) :> char }))
 
+N2.X.xMain ()
+
 
 /*
 BEGIN-OUTPUT
@@ -65,5 +104,11 @@
 14
 15
 foobar
+E.F(obj,int)
+E.F(obj,string)
+B.F(int)
+E.F(obj,string)
+C.F(obj)
+C.F(obj)
 END-OUTPUT
 */

Modified: nemerle/trunk/ncc/typing/Typer-OverloadSelection.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer-OverloadSelection.n	(original)
+++ nemerle/trunk/ncc/typing/Typer-OverloadSelection.n	Thu May  4 22:09:27 2006
@@ -152,6 +152,15 @@
     }
     
 
+    static AintExtension (o : OverloadPossibility) : bool
+    {
+      match (o.Member) {
+        | meth is IMethod => ! meth.IsExtensionMethod
+        | _ => true
+      }
+    }
+
+
     static AintVarArgs (o : OverloadPossibility) : bool
     {
       !o.VarArgs
@@ -163,6 +172,7 @@
       ! o.DidMamboJumbo
     }
 
+
     static AintGeneric (o : OverloadPossibility) : bool
     {
       ! o.IsGeneric
@@ -174,7 +184,14 @@
       match (parms) {
         | [] | [_] => parms
         | _ =>
-          def res = GetMinimal (parms, IsBetterOverload);
+          def res = parms;
+
+          def res =
+            if (List.Exists (res, AintExtension))
+              List.RevFilter (res, AintExtension)
+            else res;
+            
+          def res = GetMinimal (res, IsBetterOverload);
 
           def res =
             if (List.Exists (res, AintVarArgs))



More information about the svn mailing list