redhat-developer / redhat-developer/vscode-java
Extended generic type loses more specific type when using recursive type bound (works in IntelliJ)
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 2.3k
- Fork
- 546
- Merge trung bình
- 20 giờ 1 phút
- Pull request đã merge (30 ngày)
- 11
Mô tả
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)
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện kết quả hover hoặc định nghĩa với các ví dụ Fruit.java và Apple.java, sử dụng thiết lập VS Code và Java extension được báo cáo. So sánh kiểu được suy luận với dạng wildcard đệ quy mong đợi. Hoàn tất khi cửa sổ định nghĩa báo Fruit\u003c? extends Fruit\u003c?\u003e\u003e thay vì Fruit\u003c?\u003e cho ví dụ này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java, vscode
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100