@module on an @instanceOf type is silently ignored

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

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

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

研究方向

Start by reading the compiler handling for @module, @scope, and @instanceOf type declarations, then trace the generated JavaScript for the example. Check how @module on an external declaration is represented and tested. Done means the class check either uses the imported or scoped class correctly, or the compiler rejects these attributes on a type declaration.

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

描述

@module on an @instanceOf type is silently ignored. The class check then reads a global with the class name, instead of importing the class from the module.

@instanceOf("Object3D") type object3D
@module("three") @instanceOf("Mesh") type mesh = private object3D

@unboxed
type shape = Mesh(mesh) | Other(object3D)

let isMesh = (s: shape) =>
  switch s {
  | Mesh(_) => true
  | Other(_) => false
  }

compiles without a warning to

function isMesh(s) {
  return s instanceof Mesh;
}

There is no import of three. At runtime Mesh is not defined, so the check throws a ReferenceError, unless some other script happens to define a global Mesh.

Expected: either the check uses the imported class, like a @module("three") external would, or @module on a type declaration is a compile error.

@scope("THREE") is ignored the same way: the check is still s instanceof Mesh, not THREE.Mesh.

Raised in https://github.com/rescript-lang/rescript/issues/9058#issuecomment-6658655177. Classes from local files and JS libraries need this, not only the DOM.

主要語言
OCaml
星號
7.5k
分支
485
平均合併
16 小時 51 分鐘
30 天內合併 PR
268

環境準備

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