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

Disable warnings on a per-line basis #4158

Closed
vicuna opened this issue Nov 12, 2006 · 1 comment
Closed

Disable warnings on a per-line basis #4158

vicuna opened this issue Nov 12, 2006 · 1 comment
Assignees

Comments

@vicuna
Copy link

vicuna commented Nov 12, 2006

Original bug ID: 4158
Reporter: acone
Assigned to: @mshinwell
Status: resolved (set by @mshinwell on 2016-12-07T17:40:12Z)
Resolution: fixed
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)

Bug description

If I do this in ocaml, I get a warning:

type t = Foo of int | Bar of string

let list_of_all_foos = [Foo 1; Foo 2; Foo 3]

let _ =
List.map
(fun (Foo x) -> x)
list_of_all_foos

The warning, of course, is that the pattern match is incomplete. But it happens all the time that I know which constructor some value has, and an exhaustive match would need to have a catch-all case like
| _ -> failwith "shouldn't get here"

So I have three options, none of them satisfying:

  1. Write the concise version above, and accept that I'll get a crapload of warnings.
  2. Write the concise version above, and disable incomplete-match warnings. This mutilates type safety, which sucks.
  3. Do the more pedantic, complete match, which makes code suprisingly unreadable (and in reality, no safer).

So I want to keep the warnings on in general, but disable them for lines where I know what I'm doing. I should be able to do this in code, something like this:

let _ =
List.map
(fun (Foo x) -> x) {\nowarn P}
list_of_all_foos

or maybe for a whole block of code:

DisableWarning p;;

let _ =
List.map
(fun (Foo x) -> x) {\nowarn P}
list_of_all_foos

EnableWarning p;;

I realize this is a weird thing to ask for, as it mixes a hackerish compiler directive into the language. But I can't think of any other way to do this.

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @mshinwell

This can be done with [@@@ocaml.warning].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants