diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2019-02-11 09:24:04 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-02-14 02:36:02 -0500 |
commit | 19626218566ea709b5f6f287d3c296b0c4021de2 (patch) | |
tree | d22f486e543a19670be2ae88e8e358f99e1e54fd /testsuite/tests/rename | |
parent | 1d9a1d9fb8fe0a1fea2c44c4246f102ff3e1f3a3 (diff) | |
download | haskell-19626218566ea709b5f6f287d3c296b0c4021de2.tar.gz |
Implement -Wredundant-record-wildcards and -Wunused-record-wildcards
-Wredundant-record-wildcards warns when a .. pattern binds no variables.
-Wunused-record-wildcards warns when none of the variables bound by a ..
pattern are used.
These flags are enabled by `-Wall`.
Diffstat (limited to 'testsuite/tests/rename')
-rw-r--r-- | testsuite/tests/rename/should_compile/T15957.hs | 21 | ||||
-rw-r--r-- | testsuite/tests/rename/should_compile/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/T15957_Fail.hs | 32 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/T15957_Fail.stderr | 36 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/T9437.stderr | 2 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/all.T | 1 |
6 files changed, 92 insertions, 1 deletions
diff --git a/testsuite/tests/rename/should_compile/T15957.hs b/testsuite/tests/rename/should_compile/T15957.hs new file mode 100644 index 0000000000..d684e57495 --- /dev/null +++ b/testsuite/tests/rename/should_compile/T15957.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE NamedFieldPuns #-} +module T15957 where + +data P = P { x :: Int, y :: Int } + +g1 P{..} = x + 3 -- x from .. is used +g2 P{x, ..} = x + y -- y from .. is used, even if it's in a weird style + +old P{..} | x < 5 = 10 + +-- Record wildcards in lets have different scoping rules.. they bring +-- all the identifiers into scope +do_example :: IO Int +do_example = do + let P{..} = P 1 2 + return $ x + y + +let_in_example = + let P{..} = P 1 2 + in x + 4 diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T index 0c60360e17..4d427de44f 100644 --- a/testsuite/tests/rename/should_compile/all.T +++ b/testsuite/tests/rename/should_compile/all.T @@ -166,3 +166,4 @@ test('T15798a', normal, compile, ['']) test('T15798b', normal, compile, ['']) test('T15798c', normal, compile, ['']) test('T16116a', normal, compile, ['']) +test('T15957', normal, compile, ['-Werror -Wredundant-record-wildcards -Wunused-record-wildcards']) diff --git a/testsuite/tests/rename/should_fail/T15957_Fail.hs b/testsuite/tests/rename/should_fail/T15957_Fail.hs new file mode 100644 index 0000000000..77ed3ada15 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T15957_Fail.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE NamedFieldPuns #-} +module T15957_Fail where + +data P = P { x :: Int, y :: Int } + +f1 P{..} = 1 + 3 -- nothing bound is used +f2 P{x, ..} = x + 3 -- y bound but not used +f3 P{x, y, ..} = x + y -- no bindings left, i.e. no new useful bindings introduced + +g2 P{x=a, ..} = a + 3 +g3 P{x=a, y=b, ..} = a + b +g4 P{x=0, y=0,..} = 0 +g4 _ = 0 + +-- Record wildcards in lets have different scoping rules.. they bring +-- all the identifiers into scope +do_example :: IO Int +do_example = do + let P{..} = P 1 2 + return $ 0 + +let_in_example :: Int +let_in_example = + let P{..} = P 1 2 + in 0 + +data Q = Q { a, b :: P } + +nested :: Q -> Int +nested Q { a = P{..}, .. } = (case b of (P x1 _) -> x1) + diff --git a/testsuite/tests/rename/should_fail/T15957_Fail.stderr b/testsuite/tests/rename/should_fail/T15957_Fail.stderr new file mode 100644 index 0000000000..54d77c189b --- /dev/null +++ b/testsuite/tests/rename/should_fail/T15957_Fail.stderr @@ -0,0 +1,36 @@ + +T15957_Fail.hs:7:6: error: [-Wunused-record-wildcards (in -Wall), -Werror=unused-record-wildcards] + No variables bound in the record wildcard match are used + Possible fix: omit the ‘..’ + +T15957_Fail.hs:8:9: error: [-Wunused-record-wildcards (in -Wall), -Werror=unused-record-wildcards] + No variables bound in the record wildcard match are used + Possible fix: omit the ‘..’ + +T15957_Fail.hs:9:12: error: [-Wredundant-record-wildcards (in -Wall), -Werror=redundant-record-wildcards] + Record wildcard does not bind any new variables + Possible fix: omit the ‘..’ + +T15957_Fail.hs:11:11: error: [-Wunused-record-wildcards (in -Wall), -Werror=unused-record-wildcards] + No variables bound in the record wildcard match are used + Possible fix: omit the ‘..’ + +T15957_Fail.hs:12:16: error: [-Wredundant-record-wildcards (in -Wall), -Werror=redundant-record-wildcards] + Record wildcard does not bind any new variables + Possible fix: omit the ‘..’ + +T15957_Fail.hs:13:15: error: [-Wredundant-record-wildcards (in -Wall), -Werror=redundant-record-wildcards] + Record wildcard does not bind any new variables + Possible fix: omit the ‘..’ + +T15957_Fail.hs:20:9: error: [-Wunused-record-wildcards (in -Wall), -Werror=unused-record-wildcards] + No variables bound in the record wildcard match are used + Possible fix: omit the ‘..’ + +T15957_Fail.hs:25:9: error: [-Wunused-record-wildcards (in -Wall), -Werror=unused-record-wildcards] + No variables bound in the record wildcard match are used + Possible fix: omit the ‘..’ + +T15957_Fail.hs:31:18: error: [-Wunused-record-wildcards (in -Wall), -Werror=unused-record-wildcards] + No variables bound in the record wildcard match are used + Possible fix: omit the ‘..’ diff --git a/testsuite/tests/rename/should_fail/T9437.stderr b/testsuite/tests/rename/should_fail/T9437.stderr index 8c2222ef97..2b8ec84502 100644 --- a/testsuite/tests/rename/should_fail/T9437.stderr +++ b/testsuite/tests/rename/should_fail/T9437.stderr @@ -1,2 +1,2 @@ -T9437.hs:8:12: You cannot use `..' in a record update +T9437.hs:8:18: You cannot use `..' in a record update diff --git a/testsuite/tests/rename/should_fail/all.T b/testsuite/tests/rename/should_fail/all.T index ce8c5c9a13..af382b1a0c 100644 --- a/testsuite/tests/rename/should_fail/all.T +++ b/testsuite/tests/rename/should_fail/all.T @@ -145,3 +145,4 @@ test('T16002', normal, compile_fail, ['']) test('T16114', normal, compile_fail, ['']) test('T16116b', normal, compile_fail, ['']) test('ExplicitForAllRules2', normal, compile_fail, ['']) +test('T15957_Fail', normal, compile_fail, ['-Werror -Wall -Wno-missing-signatures']) |