Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 488016

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: CoreAssignee: 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:

Description Raffaele Dell\'Aversana CLA 2016-02-18 08:06:24 EST
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));
	}
}
//------------------------------------------------------------
Comment 1 Raffaele Dell\'Aversana CLA 2016-02-18 08:07:26 EST
Code is for Java 1.8+
Comment 2 Stephan Herrmann CLA 2016-02-18 09:12:41 EST
Thanks, I can reproduce - and have seen that kind of trouble before ...

*** This bug has been marked as a duplicate of bug 481133 ***