RFR: 8334037: Local class creation in lambda in pre-construction context crashes javac

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Jun 26 11:05:35 UTC 2024


On Wed, 26 Jun 2024 11:00:23 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> As we recently [moved](https://github.com/openjdk/jdk/pull/19836) the translation of "simple" method references from `LambdaToMethod` to `Lower`, it became clearer that this step in fact would benefit from running even *earlier*, as it depends on the synthetic casts generated by `TransTypes` (e.g. if one or more desugared lambda parameters have a type that is either an intersection or a union type).
> Moving the translation earlier would allow us not to *guess* which casts would need to be introduced, and just running `TransTypes::translate` on the desugaring code would take into account the type mismatches.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java line 556:

> 554:             result = translate(conv.lambda());
> 555:         } else {
> 556:             Type t = types.skipTypeVars(tree.expr.type, false);

This part is just the old `visitReference`

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java line 657:

> 655:      * Converts a method reference which cannot be used directly into a lambda
> 656:      */
> 657:     private class MemberReferenceToLambda {

I've considered adding a completely new step for this, but decided against it, as for now there is an assumption that `TransTypes` is the first translation step after `Flow`, and we run a scanner before it to collect usages of various features, as well as supertype/subtype ordering information (as `TransTypes` needs to be run in a certain order - e.g. supertypes first).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19903#discussion_r1654608312
PR Review Comment: https://git.openjdk.org/jdk/pull/19903#discussion_r1654610189


More information about the compiler-dev mailing list