Incorrect type inference for Assign Return Value To New Variable
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### 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:
```java
List list = Collections.emptyList();
list.stream().collect(Collectors.groupingBy(CharSequence::toString));
```
Performing "Assign Return Value To New Variable" on the collect() call results in:
```java
Map> collect = list.stream().collect(Collectors.groupingBy(CharSequence::toString));
```
However, this is incorrect and doesn't compile.
A correct result would be:
```java
Map> 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
Contributor guide
Research direction
Start with the Java Hints implementation behind “Assign Return Value To New Variable” and reproduce the supplied stream and groupingBy example. Trace how the collect() result type is inferred, then verify that the generated declaration accounts for wildcard captures and compiles as shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100