Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004158OCamlOCaml generalpublic2006-11-12 19:052006-11-15 12:26
Reporteracone 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
StatusacknowledgedResolutionopen 
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 _ =
  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.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2006-11-12 19:05 acone New Issue
2006-11-15 12:26 doligez Status new => acknowledged


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker