Printed type declarations drop @tag, @notUndefined and runtime annotations

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

維護者通常 1 天內回覆

已經有一個關聯 PR 被合併了。

  • #9136 來自 @cknitt —— 已合併

評估

難度
4/5
預估耗時
1-2 天
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
ocaml
領域
compilers

研究方向

Start with Printtyp.tree_of_type_decl, which the issue identifies as the printer used by error messages, hover, and createInterface. Compare its handling of @unboxed and @immediate with @tag, @notUndefined, @typeOf, and @instanceOf; use the named expected-output files and the applied-functor example to check the affected paths. Done means printed declarations retain these annotations in diagnostics, hover, and generated interfaces. An open linked pull request already tracks the work.

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

描述

Printed type declarations keep @unboxed and @immediate, but drop the other annotations of a declaration: @tag, @notUndefined and the runtime annotations (@typeOf, @instanceOf). @as on fields and constructors is kept. The printer is Printtyp.tree_of_type_decl, used by error messages, hover and createInterface.

Error messages. The declaration the message is about is printed without the annotation it names:

module M: {
  @tag("kind") type v = Circle({r: float}) | Square({side: float})
} = {
  @tag("type") type v = Circle({r: float}) | Square({side: float})
}
Type declarations do not match:
  type v = Circle({r: float}) | Square({side: float})
is not included in
  type v = Circle({r: float}) | Square({side: float})
...
Their @tag annotations differ.

The same happens with @notUndefined (tests/build_tests/super_errors/expected/not_undefined_functor_argument.res.expected, where the expected side prints as type t) and with @typeOf (runtime_annotation_interface_over_record.res.expected).

Generated interfaces. createInterface prints a type when it cannot copy its source, as for a type of an applied functor. The annotation is lost and the interface does not match its implementation:

module Make = (X: {type t}) => {
  @tag("kind") type wrapped = Value({value: X.t}) | Empty({reason: string})
}

module Applied = Make({
  type t = int
})

The generated interface has module Applied: { type wrapped = Value({value: int}) | Empty({reason: string}) }, and compiling it with the implementation fails:

In module Applied:
Type declarations do not match:
  type wrapped = Applied.wrapped = Value({value: int}) | Empty({reason: string})
is not included in
  type wrapped = Value({value: int}) | Empty({reason: string})
...
Their @tag annotations differ.

Hover prints types the same way, so it hides these annotations too.

主要語言
OCaml
星號
7.5k
分支
484
平均合併
17 小時 2 分鐘
30 天內合併 PR
249

環境準備

在 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 摘要。