redhat-developer / redhat-developer/vscode-java
Extended generic type loses more specific type when using recursive type bound (works in IntelliJ)
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 2.3k
- 派生
- 547
- 平均合并
- 20 小时 1 分钟
- 30 天内合并 PR
- 11
描述
The inferred type when using recursive type bounds is missing a more specific wildcard when looking at the definition of a variable (e.g. via hovering it). This works in IntelliJ, but not in VS Code.
VS Code:
Fruit<?>
IntelliJ:
Fruit<? extends Fruit<?>>
Environment
- Operating System: macOS Sonoma 14
- JDK version: 21.0.2
- Visual Studio Code version: 1.94.2
- Java extension version: v0.29.0
Steps To Reproduce
Here is a made-up example with two classes:
Fruit.java
public class Fruit<T extends Fruit<T>> implements Comparable<T> {
private final Integer size;
public Fruit(Integer size) {
this.size = size;
}
public Integer getSize() {
return size;
}
@Override public int compareTo(T other) {
return size.compareTo(other.getSize()); // Now getSize() is available.
}
}
Apple.java
class Apple extends Fruit<Apple> {
public Apple(Integer size) {
super(size);
}
}
Some random class/function to check:
public Fruit<? extends Fruit<?>> getFruit(Fruit<? extends Fruit<?>> someFruit) {
// in real world code, assume some mapper/runtime check here
// var someFruit = ...
return new Fruit<>(1);
}
Somewhere else:
var fruit = getFruit(new Apple(1));
Current Result
Fruit<?> (in the definition window)
Expected Result
Fruit<? extends Fruit<?>> (in the definition window)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用报告中的 VS Code 和 Java 扩展设置,通过 Fruit.java 和 Apple.java 示例复现悬停或定义结果。将推断出的类型与预期的递归通配符形式进行比较。当定义窗口针对该示例报告 Fruit\u003c? extends Fruit\u003c?\u003e\u003e 而不是 Fruit\u003c?\u003e 时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, vscode
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100