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

Alert floating attributes in mli are ignored #6820

Closed
david-maison-TrustInSoft opened this issue Jan 3, 2023 · 6 comments
Closed

Alert floating attributes in mli are ignored #6820

david-maison-TrustInSoft opened this issue Jan 3, 2023 · 6 comments
Labels

Comments

@david-maison-TrustInSoft

Reproduction

With the following files:

$ cat dune
(executable
 (name bar)
 (flags (-alert +all))
 (modules foo bar))

$ cat dune-project
(lang dune 2.7)

$ cat bar.ml
let () = print_endline Foo.x

$ cat foo.ml
let x = "Hello"

$ cat foo.mli
[@@@alert unsafe "Reason: it's not safe."]

val x : string

Run dune build.

Expected Behavior

dune build should exit 0 (or 1 if alerts are fatal) with an error message as we can observe with the following command line:

$ ocamlc -c -alert +all foo.mli foo.ml bar.ml
File "bar.ml", line 1, characters 23-28:
1 | let () = print_endline Foo.x
                           ^^^^^
Alert unsafe: module Foo
Reason: it's not safe.

Actual Behavior

dune build exits 0 without printing anything.

Specifications

  • Version of dune (output of dune --version): 3.6.1
  • Version of ocaml (output of ocamlc --version): 4.14.0
  • Operating system (distribution and version): Ubuntu 22.04.1 LTS

Additional information

If the attribute is attached to the val x declaration, it works correctly. A workaround would be to remove the floating attribute and add an item attribute for each declaration.

Same problem with deprecated or ocaml.deprecated attributes.

@Alizter
Copy link
Collaborator

Alizter commented Jan 3, 2023

I checked and ocamlopt doesn't output any warning either, so perhaps this is really an upstream OCaml bug.

@Alizter
Copy link
Collaborator

Alizter commented Jan 3, 2023

Here is a self contained test btw:

  $ cat > dune << EOF
  > (executable
  >  (name bar)
  >  (flags (-alert +all))
  >  (modules foo bar))
  > EOF

  $ cat > dune-project << EOF
  > (lang dune 2.7)
  > EOF

  $ cat > bar.ml << EOF
  > let () = print_endline Foo.x
  > EOF

  $ cat > foo.ml << EOF
  > let x = "Hello"
  > EOF

  $ cat > foo.mli << EOF
  > [@@@alert unsafe "Reason: it's not safe."]
  > 
  > val x : string
  > EOF

  $ ocamlc foo.mli
  $ ocamlc foo.ml

  $ ls
  a.out
  bar.ml
  dune
  dune-project
  foo.cmi
  foo.cmo
  foo.ml
  foo.mli

  $ dune build bar.exe --display=short
      ocamldep .bar.eobjs/bar.ml.d
      ocamldep .bar.eobjs/foo.mli.d
      ocamldep .bar.eobjs/foo.ml.d
        ocamlc .bar.eobjs/byte/dune__exe.{cmi,cmo,cmt}
      ocamlopt .bar.eobjs/native/dune__exe.{cmx,o}
        ocamlc .bar.eobjs/byte/dune__exe__Foo.{cmi,cmti}
        ocamlc .bar.eobjs/byte/dune__exe__Bar.{cmi,cmo,cmt}
      ocamlopt .bar.eobjs/native/dune__exe__Foo.{cmx,o}
      ocamlopt .bar.eobjs/native/dune__exe__Bar.{cmx,o}
      ocamlopt bar.exe

  $ ls _build/default
  bar.exe
  bar.ml
  foo.ml
  foo.mli

@nojb
Copy link
Collaborator

nojb commented Jan 4, 2023

Is this an instance of #6115?

@nojb
Copy link
Collaborator

nojb commented Jan 4, 2023

Is this an instance of #6115?

Answering to myself: no, it is a side-effect of the "wrapped executables" feature of Dune (so a bug). You will see the alert if you add (wrapped_executables false) to your dune-project.

@nojb nojb added the bug label Jan 4, 2023
@david-maison-TrustInSoft
Copy link
Author

Thanks for your prompt responses! I confirm that (wrapped_executables false) (resp. (wrapped false) in the dune file for libraries) can be used as a workaround.

@nojb
Copy link
Collaborator

nojb commented Jan 4, 2023

See ocaml/ocaml#11867 for the upstream report.

@rgrinberg rgrinberg closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants