From 046432951016679dc231a8de48b067d8748f23b4 Mon Sep 17 00:00:00 2001 From: Gabriel Scherer Date: Sat, 15 Aug 2015 20:24:33 +0200 Subject: [PATCH] small testsuite for shadowing warnings --- testsuite/tests/warnings/w44.ml | 168 +++++++++++++++++++++++++ testsuite/tests/warnings/w44.reference | 24 ++++ 2 files changed, 192 insertions(+) create mode 100644 testsuite/tests/warnings/w44.ml create mode 100644 testsuite/tests/warnings/w44.reference diff --git a/testsuite/tests/warnings/w44.ml b/testsuite/tests/warnings/w44.ml new file mode 100644 index 000000000000..f0115ba09d8b --- /dev/null +++ b/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; + () diff --git a/testsuite/tests/warnings/w44.reference b/testsuite/tests/warnings/w44.reference new file mode 100644 index 000000000000..fbc9b8c2cda2 --- /dev/null +++ b/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)