@module on an @instanceOf type is silently ignored

Abierto
#9,239 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
54/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, ocaml
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
OCaml
Estrellas
7.5k
Forks
485
Merge medio
16 h 51 min
PR fusionados (30 d)
268

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rescript-lang/rescript

Todos los issues de rescript-lang/rescript

Issues similares

Más issues de Compilers

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.