try...finally block ignores return as "early exit"

Đang mở
#5,608 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
57/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ệ
python, rust
Lĩnh vực
devtools, testing

Hướng nghiên cứu

Start by reproducing the reported behavior in the linked Pyrefly sandbox, then read the type-checker's control-flow handling for try...finally and early returns. The issue does not name source files or tests, so locate the relevant regression coverage before changing anything. Done means the else branch in finally is no longer reported unreachable when the try block returns early.

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

Mô tả

Describe the Bug

pyrefly ignores a "return" as block exit and evaluates ok to be "True" at the end of the block. I think this is an regression coming from 1.4.0 to 1.4.1, but I didn't verify the exact version number.

import random

def func():
    ok: bool = False

    try:
        if random.randint(0, 10) == 5:
            return
        ok = True
    finally:
        if ok:
            print('I am ok')
        else:
            print('Unreachable, eh?') # <!-- tells us this is unreachable

func()
Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pZQ_D4IwEMW_yiUM1cRQHFxY3EzcXNxcKhIwBGoA_fy-65-0JZHFieTaeyn3fvd-RabbvBE13cdkbjwiuivpjg3Gs04KYPgVCAN2WFqNnD_sT7GjfbFlkw_RvQBcqOkO2uygLaUWOHG8IhWxEIgzqR6HAiT4kwW90eXrADaq1uZh3R65C5abvzWjXhid0cUWyM0MEQdCmjeCFM7ntyFDhtbUzvNrKqX07XpsZD3Ih64mmXRIYqbVRz1NPKdypA2YE2T_IUxYwMQaX4Lxwo1VZL4

(Only applicable for extension issues) IDE Information

No response

Ngôn ngữ chính
Rust
Star
7.2k
Fork
578
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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 facebook/pyrefly

Tất cả issue của facebook/pyrefly

Issue tương tự

Thêm issue về Rust

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.