TheSpyder / rescript-webapi

ReScript bindings to the DOM and other Web APIs
http://tinymce.github.io/rescript-webapi/api/Webapi/
Other
149 stars 36 forks source link

Error with "@as": expect int, string literal or json literal {json|text here|json} #92

Closed malthe closed 2 years ago

malthe commented 2 years ago

I am getting some errors trying to build my app.

In line 43, @as is highlighted.

This is with rescript-compiler from tag 9.1.4 built with OCaml 4.10.2+rescript.

$ node_modules/.bin/rescript build -with-deps
Dependency on rescript-webapi
rescript: [7/352] src/Webapi/Dom/Webapi__Dom__GlobalEventHandlers.ast
FAILED: src/Webapi/Dom/Webapi__Dom__GlobalEventHandlers.ast

  We've found a bug for you!
  /rescript-webapi/src/Webapi/Dom/Webapi__Dom__GlobalEventHandlers.res:43:5-7

  41 ┆ external removeSelectionChangeEventListenerUseCapture: (
  42 ┆   T.t,
  43 ┆   @as("selectionchange") _,
  44 ┆   Dom.focusEvent => unit,
  45 ┆   @as(json`true`) _,

  expect int, string literal or json literal {json|text here|json}

What am I doing wrong?

TheSpyder commented 2 years ago

Which version of webapi are you using?

[edit] I can see these @as lines are there in the current code… this compiles just fine for everyone using a ReScript release though. Why are you using one you compiled yourself? Are you able to try a release version to confirm?

This might be something that’s changing in ReScript 10, which would be good to know.

malthe commented 2 years ago

I have also tried ReScript 9.1.4. Same result. This is both the latest release and I have tried master branch as well.

Might it have to do with the OCaml release?

TheSpyder commented 2 years ago

ReScript shouldn’t change based on the OCaml release it’s compiled with.

I’m very interested in solving compatibility problems like this but I (and others) have been using webapi with 9.1.4 for months.

I wonder if something else about your project is causing this. Are you able to share (or build) a replication case?

malthe commented 2 years ago

Seems to be related to this: https://forum.rescript-lang.org/t/string-literal-syntax/2821.

I must have made some mistake because I intended to be on 9.1.4 and not master; what I had sought for was to compile my own rescript with a more recent OCaml, i.e., 4.10.2+rescript and so I was building the rescript compiler from source.

TheSpyder commented 2 years ago

OK, so this might be a ReScript 10 incompatibility. It could still be reverted as a mistake; I will wait until the change is available in an official pre-release build before making any adjustments. I will open a new ticket at that time.

Compiling ReScript with a newer OCaml should make no difference to the compiler itself, other than making it faster on Apple Silicon computers. I suggest sticking with the 9.1.4 release for now (or there is a pre-release v10 build if you really want faster M1 support).

malthe commented 2 years ago

Oh it wasn't really speed I was looking for, but just compatibility with other parts of the OCaml toolchain.

TheSpyder commented 2 years ago

ah, using a newer OCaml compiler won't help with that either. The ReScript compiler is based on OCaml 4.06 semantics and they have shown little interest in upgrading it.

If you'd like better compatibility with OCaml try melange. It's a fork of ReScript from back when it was called BuckleScript, upgraded with all the latest OCaml features (and it tries to keep up to date with ReScript features too).

malthe commented 2 years ago

I'll check that out thanks. By the way, I do think they are somewhat committed to a newer version since they published https://opam.ocaml.org/packages/ocaml-variants/ocaml-variants.4.10.2+rescript/.

TheSpyder commented 2 years ago

They are committed to compiling ReScript on a newer ocaml version. That doesn’t mean they will adopt any of the language changes, just that it helps them stay up to date with things like apple silicon support.