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
- 平均合并
- 19 小时 35 分钟
- 30 天内合并 PR
- 208
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rescript-lang/rescript 的其他 Issue
-
Per-constructor @unboxed is not compared across interfaces or coercions可能已有人在做 @cknitt 今天认领。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
rescript-lang/rescript#9038 ·
维护者通常 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 天内回复
-
@notUndefined in an interface is not checked against the implementation可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
rescript-lang/rescript#8964 · 1 条评论 ·
维护者通常 1 天内回复
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
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 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 85/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
build
难度 2/5 1-3 小时 新手友好度 65/100
AOMediaCodec/SVT-AV1#2500 ·