Skip to content

Incorrect type inference for Assign Return Value To New Variable #9159

@nmatt

Description

@nmatt

Apache NetBeans version

Apache NetBeans 28

What happened

Assign Return Value To New Variable in some cases yields code that doesn't compile due to type errors. See the example below.

Language / Project Type / NetBeans Component

Java, Hints

How to reproduce

Example:

List<? extends CharSequence> list = Collections.emptyList();
list.stream().collect(Collectors.groupingBy(CharSequence::toString));

Performing "Assign Return Value To New Variable" on the collect() call results in:

Map<String, List<? extends CharSequence>> collect = list.stream().collect(Collectors.groupingBy(CharSequence::toString));

However, this is incorrect and doesn't compile.

A correct result would be:

Map<String, ? extends List<? extends CharSequence>> collect = list.stream().collect(Collectors.groupingBy(CharSequence::toString));

Maybe wildcard captures aren't considered correctly.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows

JDK

NetBeans runs on JDK 21, the project is JDK 17

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

No response

Are you willing to submit a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)kind:bugBug report or fixneeds:triageRequires attention from one of the committers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions