Skip to content

Commit 2ea0d2d

Browse files
committed
#76: Workaround compiler bug introduced by #67
1 parent 6e0d7ce commit 2ea0d2d

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

core/src/main/java/fj/control/Trampoline.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ public <B> Trampoline<B> bind(final F<A, Trampoline<B>> f) {
5252
// The resumption of a Codense is the resumption of its subcomputation. If that computation is done, its result
5353
// gets shifted into the continuation.
5454
public Either<P1<Trampoline<A>>, A> resume() {
55-
return left(
56-
sub.resume().either(
57-
p -> p.map(ot -> ot.fold(o1 -> o1.foldNormal(o2 -> cont.f(o2), t -> t._1().bind(cont)),
58-
c -> codense(c.sub, o -> c.cont.f(o).bind(cont)))),
59-
o3 -> P.lazy(u -> cont.f(o3))
60-
)
61-
);
55+
return left(sub.resume().either(p -> {
56+
return p.map(ot -> {
57+
// WARNING: In JDK 8, update 25 (current version) the following code is a
58+
// workaround for an internal JDK compiler error, likely due to
59+
// https:bugs.openjdk.java.net/browse/JDK-8062253.
60+
F<Normal<Object>, Trampoline<A>> f = o -> o.foldNormal(o1 -> cont.f(o1), t -> t._1().bind(cont));
61+
F<Codense<Object>, Trampoline<A>> g = c -> codense(c.sub, o -> c.cont.f(o).bind(cont));
62+
return ot.fold(f, g);
63+
});
64+
}, o -> P.lazy(u -> cont.f(o))));
6265
}
6366
}
6467

core/src/main/java/fj/data/List.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ public final Iterator<A> iterator() {
7878
* @return The length of this list.
7979
*/
8080
public final int length() {
81-
return foldLeft(i -> a -> i + 1, 0);
81+
// WARNING: In JDK 8, update 25 (current version) the following code triggers an internal JDK compiler error, likely due to https://bugs.openjdk.java.net/browse/JDK-8062253. The code below is a workaround for this compiler bug.
82+
// return foldLeft(i -> a -> i + 1, 0);
83+
F2<Integer, A, Integer> f = (i, a) -> i + 1;
84+
return foldLeft(f, 0);
8285
}
8386

8487
/**

0 commit comments

Comments
 (0)