Skip to content

Commit

Permalink
small testsuite for shadowing warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gasche committed Aug 15, 2015
1 parent 53d949c commit 0464329
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 0 deletions.
168 changes: 168 additions & 0 deletions testsuite/tests/warnings/w44.ml
@@ -0,0 +1,168 @@
let ignore _ = ()

module Pervasives = struct
(* the evil shadower *)
let compare x y = (x, y)
let (<=) x y = (x, y)
let (mod) x y = (x, y)
let (.()) x y = (x, y)
let x = ()
end

[@@@ocaml.warning "+A"]

(* this should not warn: shadowed identifier is not used *)
let alpha compare =
ignore compare;
let open Pervasives in
x

let infix (<=) =
ignore (<=);
let open Pervasives in
x

let false_infix (mod) =
ignore (mod);
let open Pervasives in
x

let access (.()) =
ignore (.());
let open Pervasives in
x

let () =
ignore alpha;
ignore infix;
ignore false_infix;
ignore access;
()

(* this should raise 44 (the old warning) *)
let alpha compare =
ignore compare;
let open Pervasives in
compare

(* this should raise 44 (the old warning) *)
let infix (<=) =
ignore (<=);
let open Pervasives in
(<=)

let false_infix (mod) =
ignore (mod);
let open Pervasives in
(mod)

let false_infix2 (mod) a b =
ignore (mod);
let open Pervasives in
a mod b

let access (.()) =
ignore (.());
let open Pervasives in
(.())

let access2 (.()) a b =
ignore (.());
let open Pervasives in
a.(b)

let () =
ignore alpha;
ignore infix;
ignore false_infix;
ignore false_infix2;
ignore access;
ignore access2;
()

[@@@ocaml.warning "+A-44"]

(* this should raise 52 (the new warning) *)
let alpha compare =
ignore compare;
let open Pervasives in
compare

(* this should raise 53 (the new warning) *)
let infix (<=) =
ignore (<=);
let open Pervasives in
(<=)

let false_infix (mod) =
ignore (mod);
let open Pervasives in
(mod)

let false_infix2 (mod) a b =
ignore (mod);
let open Pervasives in
a mod b

let access (.()) =
ignore (.());
let open Pervasives in
(.())

let access2 (.()) a b =
ignore (.());
let open Pervasives in
a.(b)


let () =
ignore alpha;
ignore infix;
ignore false_infix;
ignore false_infix2;
ignore access;
ignore access2;
()

[@@@ocaml.warning "-A"]

(* this shouldn't raise anything *)

let alpha compare =
ignore compare;
let open Pervasives in
compare

let infix (<=) =
ignore (<=);
let open Pervasives in
(<=)

let false_infix (mod) =
ignore (mod);
let open Pervasives in
(mod)

let false_infix (mod) a b =
ignore (mod);
let open Pervasives in
a mod b

let access (.()) =
ignore (.());
let open Pervasives in
(.())

let access2 (.()) a b =
ignore (.());
let open Pervasives in
a.(b)

let () =
ignore alpha;
ignore infix;
ignore false_infix;
ignore false_infix2;
ignore access;
ignore access2;
()
24 changes: 24 additions & 0 deletions testsuite/tests/warnings/w44.reference
@@ -0,0 +1,24 @@
File "w44.ml", line 45, characters 2-34:
Warning 44: this open statement shadows the value identifier compare (which is later used)
File "w44.ml", line 51, characters 2-31:
Warning 44: this open statement shadows the value identifier <= (which is later used)
File "w44.ml", line 56, characters 2-32:
Warning 44: this open statement shadows the value identifier mod (which is later used)
File "w44.ml", line 61, characters 2-34:
Warning 44: this open statement shadows the value identifier mod (which is later used)
File "w44.ml", line 66, characters 2-32:
Warning 44: this open statement shadows the value identifier .() (which is later used)
File "w44.ml", line 71, characters 2-32:
Warning 44: this open statement shadows the value identifier .() (which is later used)
File "w44.ml", line 88, characters 2-34:
Warning 52: this open statement shadows the value identifier compare (which is later used)
File "w44.ml", line 94, characters 2-31:
Warning 53: this open statement shadows the operator ( <= ) (which is later used)
File "w44.ml", line 99, characters 2-32:
Warning 53: this open statement shadows the operator ( mod ) (which is later used)
File "w44.ml", line 104, characters 2-34:
Warning 53: this open statement shadows the operator ( mod ) (which is later used)
File "w44.ml", line 109, characters 2-32:
Warning 53: this open statement shadows the operator ( .() ) (which is later used)
File "w44.ml", line 114, characters 2-32:
Warning 53: this open statement shadows the operator ( .() ) (which is later used)

0 comments on commit 0464329

Please sign in to comment.