golo-lang icon indicating copy to clipboard operation
golo-lang copied to clipboard

Exception when adapting a golo closure to a Java8 functional interface: back from the future

Open yloiseau opened this issue 10 years ago • 1 comments

Related to #273, but more subtle...

 [1..6]: stream(): map(|v| -> v + 1)

vs.

let a = 1
 [1..6]: stream(): map(|v| -> v + a)

The second sample raises a IllegalArgumentException: not a direct method handle. Here the handle is a “real” closure, i.e. it captures values. Thus, it's no more a DirectMethodHandle, since an adaptation is done to close the value, but a BoundMethodHandle$Species_LL, that can't apparently be used as a handle for metafactory.

See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8020816 for a similar bug.

yloiseau avatar Jun 04 '15 15:06 yloiseau

Note that explicitly converting the closure fix the problem:

let a = 1
[1..6]: stream(): map(asFunctionalInterface(Function.class, |v| -> v + a)) # ok
[1..6]: stream(): map(asInterfaceInstance(Function.class, |v| -> v + a)) # ok

so we can say it's a Golo feature (explicit over implicit :wink:)

yloiseau avatar Jun 04 '15 15:06 yloiseau