Commit 4f870f84 authored by quchen's avatar quchen Committed by Ben Gamari

Conditionally show plural "s" in warnings

Redundant constraints and defaulting warnings had "constraint(s)" in
their messages; the "s" is now conditional based on the number of things
warned about.

Reviewers: hvr, austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1647
parent e58a9361
......@@ -2245,9 +2245,13 @@ warnDefaulting wanteds default_ty
foldr (unionVarSet . tyCoVarsOfCt) emptyVarSet wanteds
tidy_wanteds = map (tidyCt tidy_env) wanteds
(loc, ppr_wanteds) = pprWithArising tidy_wanteds
warn_msg = hang (ptext (sLit "Defaulting the following constraint(s) to type")
<+> quotes (ppr default_ty))
2 ppr_wanteds
warn_msg =
hang (hsep [ text "Defaulting the following"
, text "constraint" <> plural tidy_wanteds
, text "to type"
, quotes (ppr default_ty) ])
2
ppr_wanteds
; setCtLocM loc $ warnTc warn_default warn_msg }
{-
......
......@@ -875,7 +875,10 @@ constraintSynErr env kind
dupPredWarn :: TidyEnv -> [[PredType]] -> (TidyEnv, SDoc)
dupPredWarn env dups
= ( env
, ptext (sLit "Duplicate constraint(s):") <+> pprWithCommas (ppr_tidy env) (map head dups) )
, text "Duplicate constraint" <> plural primaryDups <> text ":"
<+> pprWithCommas (ppr_tidy env) primaryDups )
where
primaryDups = map head dups
tyConArityErr :: TyCon -> [TcType] -> SDoc
-- For type-constructor arity errors, be careful to report
......
B.hs:4:1: Warning:
B.hs:4:1: warning:
Top-level binding with no type signature:
answer_to_live_the_universe_and_everything :: Int
B.hs:5:12: Warning:
Defaulting the following constraint(s) to type ‘Integer’
(Enum a0)
arising from the arithmetic sequence ‘1 .. 23 * 2’ at B.hs:5:12-20
(Num a0) arising from the literal ‘1’ at B.hs:5:13
In the first argument of ‘length’, namely ‘[1 .. 23 * 2]’
In the first argument of ‘(-)’, namely ‘length [1 .. 23 * 2]’
In the expression: length [1 .. 23 * 2] - 4
B.hs:5:12: warning:
• Defaulting the following constraints to type ‘Integer’
(Enum a0)
arising from the arithmetic sequence ‘1 .. 23 * 2’ at B.hs:5:12-20
(Num a0) arising from the literal ‘1’ at B.hs:5:13
In the first argument of ‘length’, namely ‘[1 .. 23 * 2]’
In the first argument of ‘(-)’, namely ‘length [1 .. 23 * 2]’
In the expression: length [1 .. 23 * 2] - 4
A.hs:7:1: Warning:
A.hs:7:1: warning:
Top-level binding with no type signature: main :: IO ()
B.hs:4:1: Warning:
B.hs:4:1: warning:
Top-level binding with no type signature:
answer_to_live_the_universe_and_everything :: Int
B.hs:5:12: Warning:
Defaulting the following constraint(s) to type ‘Integer’
(Enum a0)
arising from the arithmetic sequence ‘1 .. 23 * 2’ at B.hs:5:12-20
(Num a0) arising from the literal ‘1’ at B.hs:5:13
In the first argument of ‘length’, namely ‘[1 .. 23 * 2]’
In the first argument of ‘(-)’, namely ‘length [1 .. 23 * 2]’
In the expression: length [1 .. 23 * 2] - 4
B.hs:5:12: warning:
• Defaulting the following constraints to type ‘Integer’
(Enum a0)
arising from the arithmetic sequence ‘1 .. 23 * 2’ at B.hs:5:12-20
(Num a0) arising from the literal ‘1’ at B.hs:5:13
In the first argument of ‘length’, namely ‘[1 .. 23 * 2]’
In the first argument of ‘(-)’, namely ‘length [1 .. 23 * 2]’
In the expression: length [1 .. 23 * 2] - 4
A.hs:7:1: Warning:
A.hs:7:1: warning:
Top-level binding with no type signature: main :: IO ()
T2245.hs:4:10: Warning:
No explicit implementation for
‘+’, ‘*’, ‘abs’, ‘signum’, ‘fromInteger’, and (either ‘negate’
or
‘-’)
In the instance declaration for ‘Num T’
T2245.hs:4:10: warning:
No explicit implementation for
‘+’, ‘*’, ‘abs’, ‘signum’, ‘fromInteger’, and (either ‘negate’
or
‘-’)
In the instance declaration for ‘Num T’
T2245.hs:5:10: Warning:
No explicit implementation for
‘fromRational’ and (either ‘recip’ or ‘/’)
In the instance declaration for ‘Fractional T’
T2245.hs:5:10: warning:
No explicit implementation for
‘fromRational’ and (either ‘recip’ or ‘/’)
In the instance declaration for ‘Fractional T’
T2245.hs:7:29: Warning:
Defaulting the following constraint(s) to type ‘T’
(Fractional b0)
arising from the literal ‘1e400’ at T2245.hs:7:29-33
(Ord b0) arising from a use of ‘<’ at T2245.hs:7:27
(Read b0) arising from a use of ‘read’ at T2245.hs:7:38-41
In the second argument of ‘(<)’, namely ‘1e400’
In the first argument of ‘(.)’, namely ‘(< 1e400)’
In the second argument of ‘(.)’, namely ‘(< 1e400) . read’
T2245.hs:7:29: warning:
• Defaulting the following constraints to type ‘T’
(Fractional b0)
arising from the literal ‘1e400’ at T2245.hs:7:29-33
(Ord b0) arising from a use of ‘<’ at T2245.hs:7:27
(Read b0) arising from a use of ‘read’ at T2245.hs:7:38-41
In the second argument of ‘(<)’, namely ‘1e400’
In the first argument of ‘(.)’, namely ‘(< 1e400)’
In the second argument of ‘(.)’, namely ‘(< 1e400) . read’
......@@ -3,11 +3,11 @@ T10971a.hs:7:1: warning:
Top-level binding with no type signature: f :: forall a. [a] -> Int
T10971a.hs:7:11: warning:
Defaulting the following constraint(s) to type ‘[]’
Foldable t0 arising from a use of ‘length’
In the expression: length x
In the expression: \ x -> length x
In an equation for ‘f’: f = \ x -> length x
• Defaulting the following constraint to type ‘[]’
Foldable t0 arising from a use of ‘length’
In the expression: length x
In the expression: \ x -> length x
In an equation for ‘f’: f = \ x -> length x
T10971a.hs:8:1: warning:
Top-level binding with no type signature:
......@@ -18,11 +18,11 @@ T10971a.hs:8:6: warning:
defined at T10971a.hs:7:1
T10971a.hs:8:13: warning:
Defaulting the following constraint(s) to type ‘[]’
Traversable t0 arising from a use of ‘fmapDefault’
In the expression: fmapDefault f x
In the expression: \ f x -> fmapDefault f x
In an equation for ‘g’: g = \ f x -> fmapDefault f x
• Defaulting the following constraint to type ‘[]’
Traversable t0 arising from a use of ‘fmapDefault’
In the expression: fmapDefault f x
In the expression: \ f x -> fmapDefault f x
In an equation for ‘g’: g = \ f x -> fmapDefault f x
T10971a.hs:9:1: warning:
Top-level binding with no type signature:
......@@ -33,10 +33,10 @@ T10971a.hs:9:6: warning:
defined at T10971a.hs:7:1
T10971a.hs:9:31: warning:
Defaulting the following constraint(s) to type ‘[]’
(Foldable t0) arising from a use of ‘length’ at T10971a.hs:9:31-36
(Traversable t0)
arising from a use of ‘fmapDefault’ at T10971a.hs:9:14-24
In the expression: length x
In the expression: (fmapDefault f x, length x)
In the expression: \ f x -> (fmapDefault f x, length x)
• Defaulting the following constraints to type ‘[]’
(Foldable t0) arising from a use of ‘length’ at T10971a.hs:9:31-36
(Traversable t0)
arising from a use of ‘fmapDefault’ at T10971a.hs:9:14-24
In the expression: length x
In the expression: (fmapDefault f x, length x)
In the expression: \ f x -> (fmapDefault f x, length x)
tcfail204.hs:10:15: Warning:
Defaulting the following constraint(s) to type ‘Double’
(Fractional a0)
arising from the literal ‘6.3’ at tcfail204.hs:10:15-17
(RealFrac a0)
arising from a use of ‘ceiling’ at tcfail204.hs:10:7-13
In the first argument of ‘ceiling’, namely ‘6.3’
In the expression: ceiling 6.3
In an equation for ‘foo’: foo = ceiling 6.3
tcfail204.hs:10:15: warning:
• Defaulting the following constraints to type ‘Double’
(Fractional a0)
arising from the literal ‘6.3’ at tcfail204.hs:10:15-17
(RealFrac a0)
arising from a use of ‘ceiling’ at tcfail204.hs:10:7-13
In the first argument of ‘ceiling’, namely ‘6.3’
In the expression: ceiling 6.3
In an equation for ‘foo’: foo = ceiling 6.3
<no location info>:
<no location info>: error:
Failing due to -Werror.
-- Test purpose:
--
-- Ensure the plural "s" in warnings is only shown if there are more than
-- one entries
{-# OPTIONS_GHC -Wredundant-constraints #-}
{-# OPTIONS_GHC -Wtype-defaults #-}
module PluralS () where
-- Defaulting type classes
defaultingNum = 123 `seq` ()
defaultingNumAndShow = show 123
-- Redundant constraints
redundantNum :: (Num a, Num a) => a
redundantNum = 123
redundantMultiple :: (Num a, Show a, Num a, Eq a, Eq a) => a
redundantMultiple = 123
PluralS.hs:15:17: warning:
• Defaulting the following constraint to type ‘Integer’
Num t0 arising from the literal ‘123’
• In the first argument of ‘seq’, namely ‘123’
In the expression: 123 `seq` ()
In an equation for ‘defaultingNum’: defaultingNum = 123 `seq` ()
PluralS.hs:17:29: warning:
• Defaulting the following constraints to type ‘Integer’
(Num a0) arising from the literal ‘123’ at PluralS.hs:17:29-31
(Show a0) arising from a use of ‘show’ at PluralS.hs:17:24-27
• In the first argument of ‘show’, namely ‘123’
In the expression: show 123
In an equation for ‘defaultingNumAndShow’:
defaultingNumAndShow = show 123
PluralS.hs:23:1: warning:
• Redundant constraint: Num a
• In the type signature for:
redundantNum :: (Num a, Num a) => a
PluralS.hs:26:1: warning:
• Redundant constraints: (Show a, Num a, Eq a, Eq a)
• In the type signature for:
redundantMultiple :: (Num a, Show a, Num a, Eq a, Eq a) => a
......@@ -7,6 +7,7 @@ test('T9230', normal, compile_without_flag('-fno-warn-tabs'), [''])
test('T10908', normal, compile, [''])
test('T11077', normal, compile, ['-fwarn-missing-exported-sigs'])
test('T11128', normal, compile, [''])
test('PluralS', normal, compile, [''])
test('DeprU',
extra_clean([
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment