RFR: 8268312: Compilation error with nested generic functional interface [v7]
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Jul 11 21:23:38 UTC 2022
On Mon, 11 Jul 2022 18:30:37 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Please review this PR, which is my proposal to fix an existing regression. This code:
>>
>>
>> import java.util.Optional;
>>
>> class App {
>> public static void main(String[] args) {
>> Optional.of("").map(outer -> {
>> Optional.of("")
>> .map(inner -> returnGeneric(outer))
>> .ifPresent(String::toString);
>> return "";
>> });
>> }
>>
>> private static <RG> RG returnGeneric(RG generic) {
>> return generic;
>> }
>> }
>>
>> is not accepted by javac but if the user passes the `-Xdiags:verbose` option then the code compiles. I tracked down the reason for this puzzling difference and I found that it is due to our diagnostic rewriters which can generate more detailed positions for error messages but in cases like the one above can trick the compiler to generate an error message too early. The code deciding if an error message should be deferred or not, depending on the position, is at `DeferredDiagnosticHandler::report`. We decide to do the rewriting if we are in diagnostics compact mode, this is why the error doesn't occur with the `-Xdiags:verbose` option. This fix will made some diagnostics to appear at a slightly different position, but won't make the compiler reject correct code. Comments?
>>
>> TIA
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>
> some missed changes
test/langtools/tools/javac/Diagnostics/compressed/T8012003b.out line 4:
> 2: T8012003b.java:31:16: compiler.err.prob.found.req: (compiler.misc.stat.expr.expected)
> 3: T8012003b.java:32:22: compiler.err.prob.found.req: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.conditional.target.cant.be.void))
> 4: T8012003b.java:33:12: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.cant.apply.symbol: kindname.method, g, java.lang.String, java.lang.Integer, kindname.class, T8012003b, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.String))))
Seems like this diagnostic is not getting compressed?
test/langtools/tools/javac/diags/examples/ProbFoundReqFragment.java line 25:
> 23:
> 24: // key: compiler.err.prob.found.req
> 25: // key: compiler.misc.kindname.class
Uhm - this sample is meant to test `compiler.misc.prob.found.req` (e.g. the fragment version). Perhaps we might need to look at the test framework that runs these diagnostic test to understand what we have to change - or what has changed - for this to work as before?
-------------
PR: https://git.openjdk.org/jdk/pull/5586
More information about the compiler-dev
mailing list