[svn] r6862: nemerle/trunk/ncc: hierarchy/ClassMembers.n hierarchy/TypeBuilder.n testsuite/positive/operat...

nazgul svnadmin at nemerle.org
Fri Nov 10 19:26:32 CET 2006


Log:
Apply patch from Aleksey fror operator return type overloading

Author: nazgul
Date: Fri Nov 10 19:26:14 2006
New Revision: 6862

Modified:
   nemerle/trunk/ncc/hierarchy/ClassMembers.n
   nemerle/trunk/ncc/hierarchy/TypeBuilder.n
   nemerle/trunk/ncc/testsuite/positive/operators.n

Modified: nemerle/trunk/ncc/hierarchy/ClassMembers.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/ClassMembers.n	(original)
+++ nemerle/trunk/ncc/hierarchy/ClassMembers.n	Fri Nov 10 19:26:14 2006
@@ -1098,7 +1098,7 @@
 
     // don't warn about the unused `Main' methods...
     when (IsStatic && name == "Main")
-      ManagerClass.Instance.MarkAsUsed (this)
+      Manager.MarkAsUsed (this)
   }
 
   // this method check the specification from CLI ECMA-335 II 9.7

Modified: nemerle/trunk/ncc/hierarchy/TypeBuilder.n
==============================================================================
--- nemerle/trunk/ncc/hierarchy/TypeBuilder.n	(original)
+++ nemerle/trunk/ncc/hierarchy/TypeBuilder.n	Fri Nov 10 19:26:14 2006
@@ -1,4 +1,4 @@
-  /*
+/*
  * Copyright (c) 2003-2005 The University of Wroclaw.
  * All rights reserved.
  *
@@ -1464,15 +1464,6 @@
           def m = x :> IMethod;
           def sub_current = get_method_type_after_subst (m, meth);
 
-          when (m.DeclaringType.Equals (this))
-            match ((sub_current, meth.GetMemType ())) {
-              | (MType.Fun (t1, r1), MType.Fun (t2, r2))
-                when t1.Fix ().Equals (t2.Fix ()) && ! r1.Fix ().Equals (r2.Fix ()) =>
-                Message.Error (meth.Location, 
-                               $"attempted return type overload on $meth and $m")
-              | _ => ()
-            };
-
           def sig_matches =
             (if (meth.Attributes %&& NemerleAttributes.Override)
               sub_current.Equals (meth.GetMemType ())
@@ -1480,8 +1471,23 @@
               (sub_current :> MType.Fun).from.Equals (meth.GetMemType ().from))
             && m.GetParameters ().Length == par_amount;
            
+
+          def is_cast_op(m : IMethod) {
+            par_amount == 1 && (m.Name == "op_Implicit" || m.Name == "op_Explicit")
+            && (m is BuiltinMethod || (m.IsStatic && (m.Attributes %&& NemerleAttributes.Public)))
+          }
+          def return_type_overload = sig_matches && // m.DeclaringType.Equals (this) &&
+            match ((sub_current, meth.GetMemType ())) {
+              | (MType.Fun (t1, r1), MType.Fun (t2, r2))
+                when t1.Fix ().Equals (t2.Fix ()) && ! r1.Fix ().Equals (r2.Fix ()) =>
+                  // allow return type overloading for implicit and explicit operators
+                  unless (is_cast_op(m) && is_cast_op(meth))
+                    Message.Error(meth.Location, $"attempted return type overload on $meth and $m");
+                  true
+              | _ => false };
+           
           // if signature of existing method is the new one
-          if (sig_matches)
+          if (sig_matches && !return_type_overload)
           {
             // check if new method does not hide or conflict with
             // existing methods in this and base type

Modified: nemerle/trunk/ncc/testsuite/positive/operators.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/operators.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/operators.n	Fri Nov 10 19:26:14 2006
@@ -128,6 +128,15 @@
   }
 }
 
+public class OpOverloaded {
+  public static @:> (x : OpOverloaded) : int {  1 }
+  public static @:> (x : OpOverloaded) : string { "ss" }
+  public static @:> (x : int) : OpOverloaded {  null }
+  public static @: (x : OpOverloaded) : int {  1 }
+  public static @: (x : OpOverloaded) : string { "ss" }
+  public static @: (x : int) : OpOverloaded {  null }
+}
+
 class B1 {
   static uncurried (f : int -> string -> bool) : void {
     assert (f (1)("3"));



More information about the svn mailing list