Coercion hint suggests the inner type when the mismatch is nested
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 75/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- ocaml
- 領域
- compilers
研究方向
修復位於 compiler/ml/error_message_utils.ml:找到從 target_type 構建 coercion 提示的位置,並將其改為使用 top_level_types。編譯 issue 中的 ReScript 片段以重現錯誤的提示。當建議的 coercion 為 (make :> unit => iterable<int>) 且範例編譯通過時完成。
由索引模型根據 Issue 內容生成。
描述
When a type mismatch is nested inside another type, the "compatible at runtime" hint suggests a coercion to the inner type instead of the whole expected type, and the suggested code doesn't compile.
let consume = (_f: unit => Iterable.t<int>) => ()
let make: unit => Generator.t<int, unit, unit> = %raw(`function* () { yield 1 }`)
let () = consume(make)
This has type: unit => Generator.t<int, unit, unit>
But this function argument is expecting: unit => Iterable.t<int>
The incompatible parts:
Generator.t<int, unit, unit> (defined as Generator.t<int, unit, unit>) vs
Iterable.t<int> (defined as iterable<int>)
Possible solutions:
- These types are compatible at runtime. You can use the coercion operator to convert to the expected type: (make :> iterable<int>)
Applying the suggestion fails with Type unit => Generator.t<int, unit, unit> is not a subtype of iterable<int>. The right suggestion is (make :> unit => iterable<int>), which compiles.
Cause
In compiler/ml/error_message_utils.ml, the hint checks Ctype.subtype on the top-level types of the trace (top_level_types, "Coercion should always target the top level types"), but builds the rewrite from target_type, which is the inner incompatible pair. Printing the top-level expected type instead should fix it.
(The doubled Generator.t<…> (defined as Generator.t<…>) in the same output is #8997.)
- 主要語言
- OCaml
- 星號
- 7.5k
- 分支
- 483
- 平均合併
- 20 小時
- 30 天內合併 PR
- 219
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
rescript-lang/rescript 的其他 Issue
-
難度 5/5 一週以上 新手友好度 12/100
rescript-lang/rescript#9044 · 2 個 reaction ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 35/100
rescript-lang/rescript#9006 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 70/100
rescript-lang/rescript#8997 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 68/100
rescript-lang/rescript#8994 ·
維護者通常 1 天內回覆
-
Have formatter insert newlines around multi-line expressions可能已有人在做 @rolandpeelen 於 3 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 25/100
rescript-lang/rescript#8960 ·
維護者通常 1 天內回覆
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
enhancement scope:diagnostics scope:syntax
難度 2/5 1-3 小時 新手友好度 77/100
-
code: refactoring good first issue
難度 2/5 1-3 小時 新手友好度 68/100
idris-lang/Idris2#3887 ·
維護者通常 1 天內回覆
-
severity: low
難度 2/5 1-3 小時 新手友好度 72/100
luainkernel/lunatik#2207 ·
維護者通常 1 天內回覆
-
backend:X86 generated by fuzzer llvm:globalisel miscompilation
難度 2/5 1-3 小時 新手友好度 72/100
llvm/llvm-project#235468 · 1 則留言 ·
維護者通常 1 天內回覆
-
area:codegen backend:cuda backend:hip bug direction:input
難度 2/5 1-3 小時 新手友好度 78/100
CrossGL/crosstl#3061 · 1 則留言 ·
維護者通常 1 天內回覆