RFR: 8240658: Code completion not working for lambdas in method invocations that require type inference

Vicente Romero vromero at openjdk.java.net
Wed Sep 9 17:50:16 UTC 2020


On Mon, 7 Sep 2020 11:28:45 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> When a method invocation requires type inference, and the user is in the process of typing of a (block) lambda that is
> a parameter to the method invocation, javac may not, in some cases, perform the type inference, which then may lead to
> non working code completion in JShell (and possibly other tools).  For example (in JShell):
> Arrays.stream(new Integer[]{1}).forEach(v -> { System.err.println(v.
> 
> and press <tab> - this leads to no proposals currently, as the type of "v" is not inferred.
> 
> The idea of the proposed patch is to improve the recovery in cases significant for cases where the text is being typed,
> and allow type inference in these cases. The type of "v" is then inferred, and the code completion works.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrRecover.java line 103:

> 101:                 if ((todo.candSym.flags() & Flags.VARARGS) == 0 &&
> 102:                     mit.args.length() > todo.candSym.type.getParameterTypes().length()) {
> 103:                     break RECOVER; //too many actual parameters, skip

question: why not covering varargs too?

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/AttrRecover.java line 151:

> 149:                                 }
> 150:                                 @Override
> 151:                                 public void visitClassDef(JCClassDecl tree) {

just wondering, shouldn't anonymous classes be avoided too?

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

PR: https://git.openjdk.java.net/jdk/pull/50


More information about the compiler-dev mailing list