unrestricted closures

Zdenek Tronicek tronicek at fel.cvut.cz
Sat Nov 15 23:59:18 PST 2008


Quoting Vladimir Kirichenko <vladimir.kirichenko at gmail.com>:

> More accurate problematic example:
>
> public class Test {
>
>          static {int ==> int} temp;
>
>          static void term() {
>                  {int==>int} t = {int i ==> if (i > 5) return; i};
>                  temp = t;
>
>          }
>
>          static int m(int i, {int ==> int} f) {
>                  int y = f.invoke(i + 5);
>                  return y;
>          }
>
>          static int caller(int i) {
>                  return m(i,temp);
>          }
>          public static void main(String... args) {
>                  term();
>                  int x = caller(5);
>                  System.out.println(x);
>          }
> }
>
> Exception in thread "main" java.lang.UnmatchedTransfer: late transfer
>          at java.lang.Jump.transfer(Jump.java:48)
>          at test.Test$3.+invoke(Test.java:12)
>          at test.Test$3.invoke(Test.java:12)
>          at test.Test.m(Test.java:18)
>          at test.Test.caller(Test.java:23)
>          at test.Test.main(Test.java:29)
> Caused by: test.Test$2
>
> And it's not the bug - code like this could appear in different cases,
> it just shows what unrestricted closures passing could raise.

Right. This is not bug but a feature because the return statement, as  
well as continue and break, are lexically bound.

Z.
-- 
Zdenek Tronicek
Department of Computer Science and Engineering
Prague                   tel: +420 2 2435 7410
http://cs.felk.cvut.cz/~tronicek




More information about the closures-dev mailing list