Diagnostics: inline-record mutability coercion gives no reason, and `throw` in `finally` warns about unreachable code

未關閉
#9,185 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
38/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
ocaml

研究方向

The throw-in-finally case points to compiler/ml/typecore.ml around lines 2920-2922, where the finally block is typed as a statement; check how warning 21 is raised for non-returning statements. The inline-record coercion error is reached through a subtype path the payload does not name, so locate it by searching for the existing plain-record mutability explanation and compare the two. Run the two snippets from the issue to confirm the wrong output, and count done as the mutable-field explanation appearing for inline records and warning 21 no longer firing for throw in finally.

由索引模型根據 Issue 內容生成。

描述

Found by differential semantic drift analysis from b123b7c3 to c10223e8.

What is broken

  • Coercion into an inline record with a mutable field gives no reason (#9086). The coercion is now rejected, correctly:

    type v1 = A({x: float})
    type v2 = A({mutable x: float})
    let a: v1 = A({x: 0.})
    let b = (a :> v2)
    

    The error is only Type v1 is not a subtype of v2. For a field of a plain record type ({r: r1} into {r: r2}) the error explains: "The field x is mutable in record r2, but not in record r1. A coercion can't make a field writable."

  • throw in finally gives warning 21 (#8931):

    exception B
    let k = () => try { 1 } finally { throw(B) }
    

    Warning 21: "This statement does not continue execution; following code is unreachable." No code follows the throw; the generated JavaScript is correct. The finally block is typed as a statement (typecore.ml L2920-L2922), and a non-returning statement triggers this warning.

Possible cause (speculation only)

The inline-record path reports the subtype failure before reaching the field comparison that produces the explanation for plain records.

🤖 Generated with Claude Code

主要語言
OCaml
星號
7.5k
分支
484
平均合併
16 小時 57 分鐘
30 天內合併 PR
258

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

rescript-lang/rescript 的其他 Issue

查看 rescript-lang/rescript 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。