Type narrowing nullable static property via class-string using null coalescing results in mixed

Đang mở
#15,732 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
28/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ệ
php
Lĩnh vực
devtools

Hướng nghiên cứu

This is a type-inference bug in PHPStan's analysis of nullable static properties accessed through a class-string variable combined with the null coalescing operator. Start by reproducing the linked playground snippet, comparing the explicit null check against the ?? form to see where the type becomes mixed. The relevant logic lives in PHPStan's expression type resolution for coalesce and property fetch nodes. Done means both forms narrow to string in a regression test.

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

Mô tả

feature-request
Bug report

Here in test 1 we manually check if the value is null after accessing it and it results in a string. In test 2 we use a null coalescing operator to compact the code a little but the end result is mixed rather than string.

Code snippet that reproduces the problem

https://phpstan.org/r/788743c2-d86d-4d21-98ad-b55e6aff5931

Expected output

Both methods of removing the null should narrow to a string.

Did PHPStan help you today? Did it make you happy in any way?

No response

Ngôn ngữ chính
PHP
Star
14.2k
Fork
972
Merge trung bình
13 giờ 25 phút
Pull request đã merge (30 ngày)
142

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 phpstan/phpstan

Tất cả issue của phpstan/phpstan

Issue tương tự

Thêm issue về PHP

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.