[Nice-commit] Nice/testsuite/compiler/typing instanceof.testsuite,1.16,1.17
Brought to you by:
bonniot
From: <bo...@us...> - 2003-11-25 14:12:34
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1:/tmp/cvs-serv8432/testsuite/compiler/typing Modified Files: instanceof.testsuite Log Message: Do not make arguments of known pure higher-order functions capture variables, since they do not escape the call. Index: instanceof.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/instanceof.testsuite,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** instanceof.testsuite 25 Nov 2003 09:43:04 -0000 1.16 --- instanceof.testsuite 25 Nov 2003 10:31:01 -0000 1.17 *************** *** 3,6 **** --- 3,9 ---- class B extends A { int life = 42; } + // An arbitrary higher-order function, that might let its argument escape. + <T,U> void use(T->U f) {} + /// PASS A a; *************** *** 261,265 **** /// PASS ! new LinkedList().foreach(A arg => { arg = new B(); if (arg instanceof B) { --- 264,268 ---- /// PASS ! use(A arg => { arg = new B(); if (arg instanceof B) { *************** *** 286,287 **** --- 289,313 ---- } }; + + /// PASS + // We know that foreach does not let its arguments escape. + A x = new A(); + new LinkedList().foreach(A arg => { + x = arg; + }); + if (x instanceof B) + assert x.life == 42; + + /// FAIL + A x = new A(); + void ?-> void f = null; + [0].foreach(int arg => { + // This anonymous function escapes, even though it is inside an arg of + // foreach. + f = () => x = new A(); + }); + if (x instanceof B) { + if (f != null) + f(); + assert x.life == 42; + } |