Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004158OCaml~DO NOT USE (was: OCaml general)public2006-11-12 19:052016-12-07 18:40
Assigned Toshinwell 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0004158: Disable warnings on a per-line basis
DescriptionIf 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 _ =
    (fun (Foo x) -> x)

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 _ =
    (fun (Foo x) -> x) {\nowarn P}

or maybe for a whole block of code:

DisableWarning p;;

let _ =
    (fun (Foo x) -> x) {\nowarn P}

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.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
shinwell (developer)
2016-12-07 18:39

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

- Issue History
Date Modified Username Field Change
2006-11-12 19:05 acone New Issue
2006-11-15 12:26 doligez Status new => acknowledged
2016-12-07 18:39 shinwell Note Added: 0016792
2016-12-07 18:40 shinwell Status acknowledged => resolved
2016-12-07 18:40 shinwell Resolution open => fixed
2016-12-07 18:40 shinwell Assigned To => shinwell
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker