hg: lambda/lambda/langtools: 8016177: structural most specific and stuckness; ...

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Jul 26 07:35:56 PDT 2013

On 26/07/13 15:19, Paul Benedict wrote:
> If I may ask, what is the "stuckness" that's been introduced in the 
> refactoring? What is stuck and why? I saw the term in the previous 
> commit too and wonder what it is referring to.
Stuckness has always been there - the term refers to both lambdas and 
method references, but let's focus on lambdas as they are easier to explain.

Suppose you have a method of the kind:

<Z> Z m(Function<Z, String> f) { ... }

and a call of the kind:

Class c = m(i->.getName());

In a normal case, to type-check the lambda we would look up the target 
type, compute the functional descriptor, derive lambda parameter types 
and then go ahead with type-checking of the lambda expression.

Here's there's a problem, as the target is Function<Z, String>, with Z 
being an inference variable; also, we know little of the lambda 
parameter type to be used, as the descriptor just say Z. As such, we say 
that the lambda expression is 'stuck' on Z - i.e. we cannot go ahead 
with type-checking the lambda until we know more about Z. Note that if 
we went ahead, instantiate Z immediately, we would just get Object 
(since we still don't know about the target type of the method call), 
which will result in an error.

So, we mark the lambda as stuck - which means let's look at the lambda 
again when some Z will be there. During overload that won't be possible, 
as Z won't be instantiated there; however, if m is selected by the 
overload resolution machinery, the target-type is thrown into the 
picture, Z is instantiated to Class, the lambda is finally type-checked 
(as it is now unstuck) and all goes well.

This is, in a nutshell, what stuckness is.

> On Fri, Jul 26, 2013 at 6:47 AM, <maurizio.cimadamore at oracle.com 
> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>     Changeset: 00274133b7d2
>     Author:    mcimadamore
>     Date:      2013-07-26 12:46 +0100
>     URL:
>     http://hg.openjdk.java.net/lambda/lambda/langtools/rev/00274133b7d2
>     8016177: structural most specific and stuckness
>     8016178: Order of unsticking functional expressions
>     Refined rules for structural most specific for lambda/method
>     references after recent changes.
>     ! src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
>     ! src/share/classes/com/sun/tools/javac/comp/Resolve.java
>     ! src/share/classes/com/sun/tools/javac/tree/JCTree.java
>     ! test/tools/javac/diags/examples/IncompatibleArgTypesInMethodRef.java
>     ! test/tools/javac/lambda/8016177/T8016177c.java
>     + test/tools/javac/lambda/8016177/T8016177c.out
>     ! test/tools/javac/lambda/methodReference/SamConversionComboTest.java
> -- 
> Cheers,
> Paul

More information about the lambda-dev mailing list