Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bs.optional + bs.deriving abstract shows warning 69 #414

Merged
merged 2 commits into from
Nov 12, 2022
Merged

Conversation

jchavarri
Copy link
Member

@anmonteiro I ran into this issue and thought on sharing it in case it can be fixed on Melange side.

As Melange in Dune is using OCaml byte default flags, and warning 69 was introduced in 4.13.0, these warnings that did not happen with ReScript are raised now on Melange.

Maybe the warning could be silenced at Melange ppx level? In bs.optional attrs?

@anmonteiro
Copy link
Member

I'm tempted not to fix this one. It aligns with dune, generally.

I tried this in native, and for the following dune file and scratch.ml file, this is the output:

;; dune
(executable
 (name scratch))


;; scratch.ml

type config = { leading : bool; trailing : bool }

$ dune build ./scratch.exe
    ocamldep .scratch.eobjs/scratch.ml.d
    ocamlopt .scratch.eobjs/native/dune__exe__Scratch.{cmx,o} (exit 2)
File "scratch.ml", line 1, characters 0-49:
1 | type config = { leading : bool; trailing : bool }
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error (warning 34 [unused-type-declaration]): unused type config.
File "scratch.ml", line 1, characters 16-31:
1 | type config = { leading : bool; trailing : bool }
                    ^^^^^^^^^^^^^^^
Error (warning 69 [unused-field]): unused record field leading.
File "scratch.ml", line 1, characters 32-47:
1 | type config = { leading : bool; trailing : bool }
                                    ^^^^^^^^^^^^^^^
Error (warning 69 [unused-field]): unused record field trailing.

@anmonteiro anmonteiro marked this pull request as ready for review November 12, 2022 17:52
@anmonteiro
Copy link
Member

There are 2 solutions downstream:

  1. actually use your record fields. Or delete the unused ones
  2. add (flags :standard -w -69) to your library stanza

Any reason preventing you from doing 1. or 2.?

@jchavarri
Copy link
Member Author

I am unsure the issue can be solved by actually using the fields, I see it more related to the way bs.deriving abstract is generating code. I refined the test in fcc6998 to show what I mean, you can see how defining a regular record does not trigger any 69 warning.

Maybe users can fix the problem by following your recommendations, but I think deriving abstract is still useful in some cases (like with optional fields), especially now that is confirmed that Melange will not include experimental optional record fields. And it might be a bit annoying to silence warnings every time it is used. Wdyt?

@anmonteiro
Copy link
Member

Thanks for clarifying the test and the difference when [@@bs.deriving abstract] is present. Let me look at it again.

@anmonteiro
Copy link
Member

This is, in fact, a problem related to code generated by bs.deriving abstract. Fix incoming.

@anmonteiro anmonteiro merged commit a66add6 into main Nov 12, 2022
@anmonteiro anmonteiro deleted the unused-records branch November 12, 2022 20:52
anmonteiro added a commit that referenced this pull request Nov 12, 2022
@jchavarri
Copy link
Member Author

Thanks!

anmonteiro added a commit that referenced this pull request Nov 12, 2022
anmonteiro added a commit to anmonteiro/opam-repository that referenced this pull request Nov 16, 2022
CHANGES:

- Disable warning 69 (`unused-field` in record) for the private record
  generated by the `bs.deriving` attribute
  ([melange-re/melange#414](melange-re/melange#414))
- Disable warning 20 (`ignored-extra-argument`) when applying
  `foo##fn arg1 arg2`
  ([melange-re/melange#416](melange-re/melange#416)):
  - in cases such as `external x : < .. > Js.t = ""`, the typechecker doesn't
    know the arity of the function, even though Melange will emit an uncurried
    function call.
- Disable warning 61 (`unboxable-type-in-prim-decl`) in `external` declarations
  ([melange-re/melange#415](melange-re/melange#415)):
  - Melange externals are substantially different from OCaml externals. This
    warning doesn't make sense in a JS runtime.
- melc: introduce `--bs-module-name` flag to specify the original file name for
  the current compilation unit
  ([melange-re/melange#413](melange-re/melange#413))
  - Dune's namespacing implementation generates modules such as
    `lib__Original_name`. Passing `--bs-module-name original_name` allows
    melange to issue correct `import` / `require` statements to the unmangled
    JS file names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants