[svn] r7074: nemerle/trunk/ncc: testsuite/positive/tail-call-opt.n typing/Typer2.n

nazgul svnadmin at nemerle.org
Fri Dec 8 19:43:35 CET 2006


Log:
Fix self tail calls in virtual functions

Author: nazgul
Date: Fri Dec  8 19:43:29 2006
New Revision: 7074

Modified:
   nemerle/trunk/ncc/testsuite/positive/tail-call-opt.n
   nemerle/trunk/ncc/typing/Typer2.n

Modified: nemerle/trunk/ncc/testsuite/positive/tail-call-opt.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/tail-call-opt.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/tail-call-opt.n	Fri Dec  8 19:43:29 2006
@@ -1,4 +1,5 @@
 using Nemerle.IO;
+using System.Console;
 
 class Tailed {
   public foo (x : int, y : int) : int {
@@ -109,6 +110,52 @@
   }
 }
 
+class Bug804 
+{
+  class Base
+  {
+    public virtual f( i : int ) : void
+    {
+      WriteLine("Base.f");
+      when( i != 0 )
+        f(i-1);
+    }
+  
+  };
+  
+  class Derived : Base
+  {
+    public base_f( i : int ) : void
+    {
+      WriteLine("Derived.base_f");
+      base.f(i);
+    }
+  
+    public override f( i : int ) : void
+    {
+      WriteLine("Derived.f");
+      when( i < 10 )
+        f(i+1);
+    }
+  
+  };
+
+  public static Run () : void {
+    def b = Base();
+    def d = Derived();
+    
+    WriteLine (typeof (this));
+    WriteLine("Calling b.f(10)");
+    b.f(10);
+    
+    WriteLine("Calling d.f(10)");
+    d.f(10);
+    
+    WriteLine("Calling d.base_f(10)");
+    d.base_f(10); 
+  }
+}
+
 module M {
   global_loop (acc : int, n : int) : int
   {
@@ -170,6 +217,7 @@
     X (30).foo ();
 
     Bug478.Test.Go ();
+    Bug804.Run ();
   }
 }
 
@@ -191,5 +239,25 @@
 int
 42
 foo
+Bug804
+Calling b.f(10)
+Base.f
+Base.f
+Base.f
+Base.f
+Base.f
+Base.f
+Base.f
+Base.f
+Base.f
+Base.f
+Base.f
+Calling d.f(10)
+Derived.f
+Calling d.base_f(10)
+Derived.base_f
+Base.f
+Derived.f
+Derived.f
 END-OUTPUT
 */

Modified: nemerle/trunk/ncc/typing/Typer2.n
==============================================================================
--- nemerle/trunk/ncc/typing/Typer2.n	(original)
+++ nemerle/trunk/ncc/typing/Typer2.n	Fri Dec  8 19:43:29 2006
@@ -187,6 +187,7 @@
           AreSelfMethodTyParms (meth, typarms)
           
         | TExpr.MethodRef (th, meth : IMethod, typarms, _) =>
+          (!(meth.Attributes %&& NemerleAttributes.Virtual) || meth.Attributes %&& NemerleAttributes.Sealed) &&
           meth.GetHeader ().id == current_fun.id &&
           Unfold (th) is TExpr.This &&
           AreSelfMethodTyParms (meth, typarms)



More information about the svn mailing list