Bug 430310 - [1.8][compiler] Functional interface incorrectly rejected as not being.
Summary: [1.8][compiler] Functional interface incorrectly rejected as not being.
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3.2   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords: core
Depends on:
Blocks:
 
Reported: 2014-03-13 13:48 EDT by Jason Zaugg CLA
Modified: 2014-03-14 10:58 EDT (History)
6 users (show)

See Also:


Attachments
Patch under consideration (10.08 KB, patch)
2014-03-14 01:01 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Zaugg CLA 2014-03-13 13:48:03 EDT
interface Func1<T1, R> {
        R apply(T1 v1);
        void other();
    }
    @FunctionalInterface // spurious error: F1<T, R> is not a functional interface
    interface F1<T1, R> extends Func1<T1, R> {
        default void other() {}
    }

or more simply:

    @FunctionalInterface // spurious error: F2<T, R> is not a functional interface
    interface F2<T1, R> extends Func1<T1, R> {
    	R apply(T1 v1);
        default void other() {}
    }

Tested with:

  Version: Kepler Service Release 1
  Build id: 20130919-0819

  Eclipse Java Development Tools Patch for Java 8 Support (BETA)	1.0.0.v20140312-1826	org.eclipse.jdt.java8patch.feature.group	Eclipse.org
Comment 1 Jason Zaugg CLA 2014-03-13 13:54:37 EDT
Sorry, my second "more simply" example is misleading.

In the straight forward case:

    @FunctionalInterface
    interface F3<T1, T2, R> {
    	R apply(T1 v1, T2 v2);
        default void other() {}
    }

no error is issued.

The bug is limited to the case where a default method overrides an abstract method from a super-interface.
Comment 2 Jason Zaugg CLA 2014-03-13 14:14:46 EDT
I think this is a duplicate of https://bugs.eclipse.org/bugs/show_bug.cgi?id=423467.

But I'm not sure how to tell if the fix for that bug, https://github.com/eclipse/eclipse.jdt.core/commit/02ca7d63ca, is included in v20140312-1826.
Comment 3 Jason Zaugg CLA 2014-03-13 17:59:51 EDT
I've just figured out, from http://git.eclipse.org/c/platform/eclipse.platform.releng.aggregator.git/commit/?id=7aa0f79a30d3f0cc859460c8280e2fb2fbd9665a, that my build does contain the fix for  https://bugs.eclipse.org/bugs/show_bug.cgi?id=423467.

The test case from that ticket works okay in my installation.

However, this report is slightly different: the abstract method and the overiden default methods are not overloaded.


In summary:

package scala.runtime.test;

// Okay, fixed in https://bugs.eclipse.org/bugs/show_bug.cgi?id=423467
interface I1 {
	int foo(String s);
}

@FunctionalInterface
interface A1 extends I1 {
	@Override
	default int foo(String s) {
		return -1;
	}

	int foo(java.io.Serializable s);
}

// Spurious "A2 is not a functional interface"
// pending https://bugs.eclipse.org/bugs/show_bug.cgi?id=430310
// Okay, fixed in https://bugs.eclipse.org/bugs/show_bug.cgi?id=423467
interface I2 {
	int foo(String s);
}

@FunctionalInterface
interface A2 extends I2 {
	@Override
	default int foo(String s) {
		return -1;
	}

	int bar(java.io.Serializable s);
}
Comment 4 Srikanth Sankaran CLA 2014-03-13 19:55:22 EDT
I'll take a look. Thanks.
Comment 5 Srikanth Sankaran CLA 2014-03-13 23:13:54 EDT
Jason, thanks for the defect report - this is not a recent regression, but a
problem that has existed for ever - one can say the fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=423467 was incomplete and did
not handle all cases it should have handled.

I am evaluating a fix.
Comment 6 Srikanth Sankaran CLA 2014-03-13 23:16:12 EDT
Changed the title to reflect the real problem. It is not that default
methods get counted - the problem stems from the incorrect handling of
a non-functional super interface type - we incorrectly conclude subtypes
cannot be functional either - which is wrong.
Comment 7 Srikanth Sankaran CLA 2014-03-14 01:01:27 EDT
Created attachment 240885 [details]
Patch under consideration
Comment 8 Srikanth Sankaran CLA 2014-03-14 04:15:14 EDT
All tests are green. Jay is doing some additional testing ...
Comment 9 Jason Zaugg CLA 2014-03-14 04:24:12 EDT
Thanks for the fast turnaround time, Srikanth! Much appreciated.

BTW, the context for this bug is our efforts at Typesafe to create a set of functional interfaces deriving from `scala.FunctionN`. Example usage: https://github.com/retronym/java-8-function1/blob/master/src/test/java/scala/runtime/test/Test.java

I temporarily worked around this bug by changing the functional interfaces to a form recognised JDT, and found that everything else is working perfectly, including lambda type parameter inference in arguments to the overloaded `func` method. Well done!
Comment 10 Srikanth Sankaran CLA 2014-03-14 06:00:25 EDT
(In reply to Jason Zaugg from comment #9)
> Thanks for the fast turnaround time, Srikanth! Much appreciated.
> 
> BTW, the context for this bug is our efforts at Typesafe to create a set of
> functional interfaces deriving from `scala.FunctionN`. Example usage:
> https://github.com/retronym/java-8-function1/blob/master/src/test/java/scala/
> runtime/test/Test.java

Sound interesting.

> I temporarily worked around this bug by changing the functional interfaces
> to a form recognised JDT, and found that everything else is working
> perfectly, including lambda type parameter inference in arguments to the
> overloaded `func` method. Well done!

Thanks a lot for the feedback - much appreciated.