| Summary: | [1.8] Eclipse accept code that contains a syntax error, and compiles it, producing wrong output. Javac rejects the code. | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Raffaele Dell\'Aversana <r.dellaversana> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | critical | ||
| Priority: | P3 | CC: | stephan.herrmann |
| Version: | 4.5.1 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 8 | ||
| Whiteboard: | |||
Code is for Java 1.8+ Thanks, I can reproduce - and have seen that kind of trouble before ... *** This bug has been marked as a duplicate of bug 481133 *** |
The following code is accepted by Eclipse and compiled, but javac gives (correctly) a syntax error. The correct line is commented. Code is adapted from original code on RosettaCode. //------------------------------------------------------------ import java.util.function.Function; public interface EclipseBug { interface RecursiveFunction<F> extends Function<RecursiveFunction<F>, F> { } public static <A, B> Function<A, B> Y(Function<Function<A, B>, Function<A, B>> f) { RecursiveFunction<Function<A, B>> r = w -> f.apply(x -> w.apply(w).apply(x)); return r.apply(r); } public static void main(String... arguments) { Function<Integer, Integer> fib = Y(f -> n -> (n <= 2) ? 1 : (f.apply(n - 1) + f.apply(n - 2))); // the following line is correct // Function<Integer, Integer> fac = Y(f -> n -> (n <= 1) ? 1 : (n * f.apply(n - 1))); //The following line contains a syntax error, but Eclipse does not detect it and compiles the code, producing wrong output Function<Integer, Integer> bug = Y(f -> n -> (n <= 1) ? 1 : (n * f.apply(n - 1)):); System.out.println("fib(10) = " + fib.apply(10)); System.out.println("fac(10) = " + fac.apply(10)); } } //------------------------------------------------------------