Lambda parameter type: a captured wildcard loses its bound (List<? extends >)

Đã đóng
#112 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
tooling

Hướng nghiên cứu

Start from ParameterizedTypePrinter, which prints ? extends with nothing after it when the wildcard is EXTENDS and has neither a type parameter nor type info. Reproduce with the q.F snippet in the issue, then inspect lambda.methodInfo().parameters().getFirst().parameterizedType() for the inner lambda. Done when the printed type keeps the bound (List<? extends T>) and the output parses again. Check with the maintainers which denotable approximation they want before choosing one.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

Problem

The type of an implicitly typed lambda parameter whose type involves a capture loses the capture's bound. ? extends T becomes ? extends with nothing after it, and prints as List<? extends >.

package q;
import java.util.List;
import java.util.function.Consumer;
public class F {
    interface Box<T> { void onComplete(Consumer<? super List<T>> c); }
    static <T> void find(List<Box<? extends T>> boxes) {
        boxes.forEach(box -> box.onComplete(result -> System.out.println(result.size())));
    }
}

For the inner lambda, lambda.methodInfo().parameters().getFirst().parameterizedType() is

java.util.List<? extends >

and lambda.concreteFunctionalType() is java.util.function.Consumer<java.util.List<? extends >>. In the model the wildcard is EXTENDS, with neither a type parameter nor a type info, so ParameterizedTypePrinter prints ? extends followed by nothing. The outer lambda's parameter is fine: q.F.Box<? extends T>.

Expected

javac types result as List<CAP#1>, where CAP#1 is the capture of ? extends T. A denotable approximation keeps the bound: List<? extends T>, and Consumer<List<? extends T>> for the functional type. At the very least the bound T should not be lost.

Why it matters

As long as the lambda stays a lambda, the parameter type is never printed. It is printed as soon as code is generated from it: a rewrite of the lambda into an anonymous class (new Consumer<List<? extends >>() { public void accept(List<? extends > result) ... }), a helper method that receives the value, or an explicitly typed lambda. The result does not parse ("illegal start of type").

Seen on

maddi 0.9.5-alpha.9. On real code: vavr io.vavr.concurrent.Future.find, list.forEach(future -> future.onComplete(result -> { ... })) with list a List<Future<? extends T>>. The parameter type comes out as io.vavr.control.Try<? extends >.

Ngôn ngữ chính
Java
Star
1
Fork
1
Merge trung bình
1 giờ 44 phút
Pull request đã merge (30 ngày)
6

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CodeLaser/maddi

Tất cả issue của CodeLaser/maddi

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.