warning when [@@deprecated] is present on exceptions

master
Hugo Heuzard 2018-04-06 19:57:18 +01:00
parent 7835cbb9bd
commit 44eb9d4a57
6 changed files with 53 additions and 4 deletions

View File

@ -62,11 +62,22 @@ let rec error_of_extension ext =
let cat s1 s2 =
if s2 = "" then s1 else s1 ^ "\n" ^ s2
let rec deprecated_of_attrs = function
let deprecated_attr x =
match x with
| ({txt = "ocaml.deprecated"|"deprecated"; _},_) -> Some x
| _ -> None
let rec deprecated_attrs = function
| [] -> None
| ({txt = "ocaml.deprecated"|"deprecated"; _}, p) :: _ ->
Some (string_of_opt_payload p)
| _ :: tl -> deprecated_of_attrs tl
| hd :: tl ->
match deprecated_attr hd with
| Some x -> Some x
| None -> deprecated_attrs tl
let deprecated_of_attrs l =
match deprecated_attrs l with
| None -> None
| Some (_,p) -> Some (string_of_opt_payload p)
let check_deprecated loc attrs s =
match deprecated_of_attrs attrs with
@ -117,6 +128,12 @@ let rec deprecated_of_str = function
| _ -> None
let check_no_deprecated attrs =
match deprecated_attrs attrs with
| None -> ()
| Some ({txt;loc},_) ->
Location.prerr_warning loc (Warnings.Misplaced_attribute txt)
let warning_attribute ?(ppwarning = true) =
let process loc txt errflag payload =
match string_of_payload payload with

View File

@ -42,6 +42,8 @@ val check_deprecated_mutable_inclusion:
def:Location.t -> use:Location.t -> Location.t -> Parsetree.attributes ->
Parsetree.attributes -> string -> unit
val check_no_deprecated : Parsetree.attributes -> unit
val error_of_extension: Parsetree.extension -> Location.error
val warning_attribute: ?ppwarning:bool -> Parsetree.attribute -> unit

View File

@ -2,6 +2,7 @@ deprecated_module_assigment.ml
deprecated_module.ml
deprecated_module_use.ml
w01.ml
w03.ml
w04_failure.ml
w04.ml
w06.ml

View File

@ -0,0 +1,4 @@
File "w03.ml", line 14, characters 8-9:
Warning 3: deprecated: A
File "w03.ml", line 17, characters 15-25:
Warning 53: the "deprecated" attribute cannot appear in this context

View File

@ -0,0 +1,24 @@
(* TEST
flags = "-w A"
* setup-ocamlc.byte-build-env
** ocamlc.byte
compile_only = "true"
*** check-ocamlc.byte-output
*)
exception A [@deprecated]
let _ = A
exception B [@@deprecated]
let _ = B
exception C [@deprecated]
let _ = B [@warning "-53"]

View File

@ -1649,6 +1649,7 @@ let transl_exception env sext =
ext, newenv
let transl_type_exception env t =
Builtin_attributes.check_no_deprecated t.ptyexn_attributes;
let contructor, newenv =
Builtin_attributes.warning_scope t.ptyexn_attributes
(fun () ->