@module on an @instanceOf type is silently ignored

オープン
#9,239 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
268

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rescript-lang/rescript のほかの issue

rescript-lang/rescript の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。