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

PPX output flags warning 53 misplaced-attribute in OCaml 5.2 #280

Open
samwgoldman opened this issue Mar 16, 2024 · 1 comment · May be fixed by #283
Open

PPX output flags warning 53 misplaced-attribute in OCaml 5.2 #280

samwgoldman opened this issue Mar 16, 2024 · 1 comment · May be fixed by #283

Comments

@samwgoldman
Copy link

Given the following contents in test.ml:

type t = string
[@@deriving show]

let () =
  print_endline (show "foo")

And a ppx binary to do the transforms:

$ ocamlfind opt -predicates ppx_driver -package ppx_deriving.show -package ppxlib.runner -linkpkg -linkall -o ppx_driver

We get the following output from ./ppx_driver test.ml

type t = string[@@deriving show]
let rec pp
  : Ppx_deriving_runtime.Format.formatter -> t -> Ppx_deriving_runtime.unit =
  ((let open! ((Ppx_deriving_runtime)[@ocaml.warning "-A"]) in
      fun fmt -> Ppx_deriving_runtime.Format.fprintf fmt "%S")
  [@ocaml.warning "-A"])
and show : t -> Ppx_deriving_runtime.string =
  fun x -> Ppx_deriving_runtime.Format.asprintf "%a" pp x[@@ocaml.warning
                                                           "-32"]
include struct let _ = fun (_ : t) -> () end[@@ocaml.doc "@inline"][@@merlin.hide
                                                                    ]
let () = print_endline (show "foo")

If we then try to compile that code:

$ ocamlopt test.pp.ml 
File "test.pp.ml", line 3, characters 4-41:
3 |   : Ppx_deriving_runtime.Format.formatter -> t -> Ppx_deriving_runtime.unit =
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Unbound module Ppx_deriving_runtime
[samgoldman@devvm20674.prn0 ~/local/ocaml5]$ ocamlfind ocamlopt -package ppx_deriving.runtime test.pp.ml 
File "test.pp.ml", line 4, characters 39-52:
4 |   ((let open! ((Ppx_deriving_runtime)[@ocaml.warning "-A"]) in
                                           ^^^^^^^^^^^^^
Warning 53 [misplaced-attribute]: the "ocaml.warning" attribute cannot appear in this context

This is from a clean switch with ocaml.5.2~alpha1 and ppx_deriving

$ opam list
# Packages matching: installed
# Name                      # Installed          # Synopsis
base-bigarray               base
base-domains                base
base-nnp                    base                 Naked pointers prohibited in the OCaml heap
base-threads                base
base-unix                   base
cppo                        1.6.9                Code preprocessor like cpp for OCaml
dune                        3.14.2               Fast, portable, and opinionated build system
ocaml                       5.2.0                The OCaml compiler (virtual package)
ocaml-compiler-libs         v0.17.0              OCaml compiler libraries repackaged
ocaml-config                3                    OCaml Switch Configuration
ocaml-option-flambda        1                    Set OCaml to be compiled with flambda activated
ocaml-option-fp             1                    Set OCaml to be compiled with frame-pointers enabled
ocaml-option-no-compression 1                    Set OCaml to be compiled with --without-zstd
ocaml-variants              5.2.0~alpha1+options First alpha release of OCaml 5.2.0
ocamlfind                   1.9.6                A library manager for OCaml
ppx_derivers                1.2.1                Shared [@@deriving] plugin registry
ppx_deriving                5.2.1                Type-driven code generation for OCaml
ppxlib                      0.32.1~5.2preview    Standard infrastructure for ppx rewriters
result                      1.5                  Compatibility Result module
sexplib0                    v0.16.0              Library containing the definition of S-expressions and some base converters
stdlib-shims                0.3.0                Backport some of the new stdlib features to older compiler
samwgoldman added a commit to samwgoldman/ppx_deriving that referenced this issue Apr 19, 2024
This fixes ocaml-ppx#280, where OCaml 5.2's new warning about unused-attributes fires.

To test, I made this change locally, pinned ppx_deriving to my fork using opam, and followed the repro case in the linked issue. With this change, the build succeeds without an unused-attribute warning.
@samwgoldman samwgoldman linked a pull request Apr 19, 2024 that will close this issue
@NathanReb
Copy link
Collaborator

You got this error when using one of the plugins right? Could you test if you still get this error when pinning ppx_deriving to the master branch?

We recently merged a port of all plugins to ppxlib and I believe this should fix the issue as they are not using the ppx_deriving API anymore and if I understand your fix in #283 correctly, this attribute was attached for all plugins by the ppx_deriving API.

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 a pull request may close this issue.

2 participants