eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
399 stars 62 forks source link

FunctionalInterfaceType for parameterized methods #6607

Open bjansen opened 8 years ago

bjansen commented 8 years ago

Given this interface:

public interface MySam {
    <T> void func(T foo);
}

public interface Consumer {
    void consumer(MySam sam);
}

The model loader's current behavior is to not consider this as a SAM. In theory, I think it could be possible to coerce it to a Anything<T>(T), but that doesn't see possible at the moment.

IntelliJ's LambdaUtil says that this interface is a valid functional interface, so in ceylon-ide-intellij I can create the corresponding FunctionalInterfaceType. When I try to use it, I get errors like these:

could not determine type of method or attribute reference: 'sam' of 'Consumer': Error while loading the com.intellij.idea/current module:
 Failure to turn functional interface to Callable type:
 Type param T not found in function Consumer.consumer() => Anything

I'm not sure who's right or wrong:

gavinking commented 8 years ago

Now, interestingly, Ceylon's type system can handle things like this, you can write an anonymous function like:

<T>(T foo) => print("hello")

Or you can take a reference to a generic method, without providing type arguments.

However, this is not functionality that is currently supported on the JVM. These are rank-2 types that we have not implemented support for yet.

So I would say: "It's not a SAM".

gavinking commented 8 years ago

More info about this thing here: https://ceylon-lang.org/blog/2015/06/03/generic-function-refs/#references_to_generic_functions

bjansen commented 8 years ago

I'm ignoring them for now in ceylon-ide-intellij, but I can still revert that when/if we decide to support them.