@module on an @instanceOf type is silently ignored

Đang mở
#9,239 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
54/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, ocaml
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

@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.

Ngôn ngữ chính
OCaml
Star
7.5k
Fork
485
Merge trung bình
16 giờ 51 phút
Pull request đã merge (30 ngày)
268

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rescript-lang/rescript

Tất cả issue của rescript-lang/rescript

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.