Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 425712 - [1.8][compiler] Valid program rejected by the compiler.
Summary: [1.8][compiler] Valid program rejected by the compiler.
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-14 22:39 EST by Srikanth Sankaran CLA
Modified: 2014-01-14 23:09 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2014-01-14 22:39:21 EST
BETA_JAVA8:

// --
public class X {
    {
        bar( () -> (char) 0); // [1]
    }
    void bar(FB fb) { }
    public static void main(String[] args) {
		System.out.println("OK");
	}
}
interface FB {
	byte foo();
}

elicits: 

The method bar(FB) in the type X is not applicable for the arguments (() -> (char) 0)

This program is valid - bug is LE.isCompatibleWith - when checking return
expressions, we should not use parameterCompatibilityLevel, we should see
if the expression is assignmenet compatible instead as would be done for
return expressions.

Expression [] returnExpressions = this.resultExpressions;
		for (int i = 0, length = returnExpressions.length; i < length; i++) {
			if (returnExpressions[i] instanceof FunctionalExpression) { // don't want to use the resolvedType - polluted from some other overload resolution candidate
				if (!returnExpressions[i].isCompatibleWith(sam.returnType, this.enclosingScope))
					return false;
			} else {
				if (this.enclosingScope.parameterCompatibilityLevel(returnExpressions[i].resolvedType, sam.returnType) == Scope.NOT_COMPATIBLE) {
					if (sam.returnType.id != TypeIds.T_void || this.body instanceof Block)
						return false;
				}
			}
		}

This is at the root of the problem reported in https://bugs.eclipse.org/bugs/show_bug.cgi?id=423803#c6