Summary
-------
While translating a method reference expression of the form Primary::m, where
m() is a method declared in a super interface of the compile time type of the expression
denoted by `Primary' AND this compile time type does not implement the method
m(), javac translates the construct with an incorrect qualifier type.
The bootstrap attribute in this case refers to the interface declaring the method,
rather than the actual receiver type (the static type of the expression `Primary'),
for example as in
```
BootstrapMethods:
0: #38 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#45 ()V
#46 REF_invokeInterface X$I.m:()V // <<<-------------------------------------
#45 ()V
```
It should actually refer to the compiler time receiver type as the qualifying class or interface of the method invocation as called
for JLS 13.1 (Point 5) which would result in bootstrap attribute being:
```
BootstrapMethods:
0: #38 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#45 ()V
#46 REF_invokeVirtual X$C.m:()V // <<<-------------------------------
#45 ()V
```
Problem
-------
Javac's translation of method reference expressions in the scenario spelled out, is not
compliant with JLS 13.1 (Point 5). Method invocation expressions are correctly handled
for the same scenario.
Solution
--------
The present fix, attempts to harmonize the translation of method reference expression with
method invocation expressions so in both cases, the qualifying class or interface of the
method invocation is computed so as to refer to the type of the receiver rather than the
method's declaring class or interface.
Specification
-------------
Relevant part of JLS is 13.1: Point 5.
"5. Given a method invocation expression or a method reference expression in
a class or interface C , referencing a method named m declared (or implicitly
declared (§9.2)) in a (possibly distinct) class or interface D , we define the
qualifying class or interface of the method invocation as follows:
• If D is Object then the qualifying class or interface of the method invocation
is Object .
• Otherwise:
– If the method is referenced by a simple name, then if m is a member of the
current class or interface C , let Q be C ; otherwise, let Q be the innermost
lexically enclosing class or interface declaration of which m is a member. In
either case, Q is the qualifying class or interface of the method invocation.
– If the expression is of the form TypeName .m or ReferenceType ::m ,
then the class or interface denoted by TypeName, or the erasure of
ReferenceType, is the qualifying class or interface of the method
invocation
– If the expression is of the form ExpressionName .m or Primary .m or
ExpressionName ::m or Primary ::m , then:
...
› Otherwise, the erasure of the compile-time type of ExpressionName or
Primary is the qualifying class or interface of the method invocation."