summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarrieMY <carrie.xmy@gmail.com>2021-07-25 12:20:13 +0800
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-07-28 13:20:17 -0400
commit7dc0dc9962e90ca8dcd01c547adab4f7c43d6090 (patch)
treeb95d911ea5c224a3b19f5f8100d044201f47cb11
parent91eb18570fae4e1982e660f6dcb4f7b69de58cf2 (diff)
downloadhaskell-7dc0dc9962e90ca8dcd01c547adab4f7c43d6090.tar.gz
Fix type check error message grammar (fixes #20122)
Remove trailing spaces
-rw-r--r--compiler/GHC/Tc/Errors.hs4
-rw-r--r--compiler/GHC/Utils/Outputable.hs21
-rw-r--r--testsuite/tests/typecheck/should_fail/T20122.hs11
-rw-r--r--testsuite/tests/typecheck/should_fail/T20122.stderr12
-rw-r--r--testsuite/tests/typecheck/should_fail/T4921.stderr7
-rw-r--r--testsuite/tests/typecheck/should_fail/T5858.stderr5
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T1
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail040.stderr16
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail043.stderr76
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail128.stderr2
10 files changed, 100 insertions, 55 deletions
diff --git a/compiler/GHC/Tc/Errors.hs b/compiler/GHC/Tc/Errors.hs
index 766b88408d..a504fd44ea 100644
--- a/compiler/GHC/Tc/Errors.hs
+++ b/compiler/GHC/Tc/Errors.hs
@@ -2522,8 +2522,8 @@ mk_dict_err ctxt@(CEC {cec_encl = implics}) (ct, (matches, unifiers, unsafe_over
= vcat [ ppWhen lead_with_ambig $
text "Probable fix: use a type annotation to specify what"
<+> pprQuotedList ambig_tvs <+> text "should be."
- , text "These potential instance" <> plural unifiers
- <+> text "exist:"]
+ , thisOrThese unifiers <+> text "potential instance" <> plural unifiers
+ <+> text "exist" <> singular unifiers <> text ":"]
mb_patsyn_prov :: Maybe SDoc
mb_patsyn_prov
diff --git a/compiler/GHC/Utils/Outputable.hs b/compiler/GHC/Utils/Outputable.hs
index 7d0436f2f2..a6d20a2467 100644
--- a/compiler/GHC/Utils/Outputable.hs
+++ b/compiler/GHC/Utils/Outputable.hs
@@ -44,7 +44,7 @@ module GHC.Utils.Outputable (
fsep, fcat,
hang, hangNotEmpty, punctuate, ppWhen, ppUnless,
ppWhenOption, ppUnlessOption,
- speakNth, speakN, speakNOf, plural, isOrAre, doOrDoes, itsOrTheir,
+ speakNth, speakN, speakNOf, plural, singular, isOrAre, doOrDoes, itsOrTheir, thisOrThese,
unicodeSyntax,
coloured, keyword,
@@ -1425,6 +1425,15 @@ plural :: [a] -> SDoc
plural [_] = empty -- a bit frightening, but there you are
plural _ = char 's'
+-- | Determines the singular verb suffix appropriate for the length of a list:
+--
+-- > singular [] = empty
+-- > singular["Hello"] = char 's'
+-- > singular ["Hello", "World"] = empty
+singular :: [a] -> SDoc
+singular [_] = char 's'
+singular _ = empty
+
-- | Determines the form of to be appropriate for the length of a list:
--
-- > isOrAre [] = text "are"
@@ -1451,3 +1460,13 @@ doOrDoes _ = text "do"
itsOrTheir :: [a] -> SDoc
itsOrTheir [_] = text "its"
itsOrTheir _ = text "their"
+
+
+-- | Determines the form of subject appropriate for the length of a list:
+--
+-- > thisOrThese [x] = text "This"
+-- > thisOrThese [x,y] = text "These"
+-- > thisOrThese [] = text "These" -- probably avoid this
+thisOrThese :: [a] -> SDoc
+thisOrThese [_] = text "This"
+thisOrThese _ = text "These" \ No newline at end of file
diff --git a/testsuite/tests/typecheck/should_fail/T20122.hs b/testsuite/tests/typecheck/should_fail/T20122.hs
new file mode 100644
index 0000000000..c9e424dbc2
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T20122.hs
@@ -0,0 +1,11 @@
+module T20122 where
+
+class Testable a where
+ test :: a -> Bool
+
+data A = A
+
+instance Testable A where
+ test _ = True
+
+foo = test
diff --git a/testsuite/tests/typecheck/should_fail/T20122.stderr b/testsuite/tests/typecheck/should_fail/T20122.stderr
new file mode 100644
index 0000000000..f3e987ee23
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T20122.stderr
@@ -0,0 +1,12 @@
+
+T20122.hs:11:7: error:
+ • Ambiguous type variable ‘a0’ arising from a use of ‘test’
+ prevents the constraint ‘(Testable a0)’ from being solved.
+ Relevant bindings include
+ foo :: a0 -> Bool (bound at T20122.hs:11:1)
+ Probable fix: use a type annotation to specify what ‘a0’ should be.
+ This potential instance exists:
+ instance Testable A
+ -- Defined at T20122.hs:8:10
+ • In the expression: test
+ In an equation for ‘foo’: foo = test
diff --git a/testsuite/tests/typecheck/should_fail/T4921.stderr b/testsuite/tests/typecheck/should_fail/T4921.stderr
index 8eff919aea..c4510cbb08 100644
--- a/testsuite/tests/typecheck/should_fail/T4921.stderr
+++ b/testsuite/tests/typecheck/should_fail/T4921.stderr
@@ -3,8 +3,9 @@ T4921.hs:10:9: error:
• Ambiguous type variables ‘a0’, ‘b1’ arising from a use of ‘f’
prevents the constraint ‘(C a0 b1)’ from being solved.
Relevant bindings include x :: a0 (bound at T4921.hs:10:1)
- Probable fix: use a type annotation to specify what ‘a0’, ‘b1’ should be.
- These potential instance exist:
+ Probable fix: use a type annotation to specify what ‘a0’,
+ ‘b1’ should be.
+ This potential instance exists:
instance C Int Char -- Defined at T4921.hs:7:10
• In the first argument of ‘fst’, namely ‘f’
In the expression: fst f
@@ -14,7 +15,7 @@ T4921.hs:12:9: error:
• Ambiguous type variable ‘b0’ arising from a use of ‘f’
prevents the constraint ‘(C Int b0)’ from being solved.
Probable fix: use a type annotation to specify what ‘b0’ should be.
- These potential instance exist:
+ This potential instance exists:
instance C Int Char -- Defined at T4921.hs:7:10
• In the first argument of ‘fst’, namely ‘f’
In the expression: fst f :: Int
diff --git a/testsuite/tests/typecheck/should_fail/T5858.stderr b/testsuite/tests/typecheck/should_fail/T5858.stderr
index 829c027135..d5474da8a4 100644
--- a/testsuite/tests/typecheck/should_fail/T5858.stderr
+++ b/testsuite/tests/typecheck/should_fail/T5858.stderr
@@ -3,8 +3,9 @@ T5858.hs:11:7: error:
• Ambiguous type variables ‘a0’, ‘a1’ arising from a use of ‘infer’
prevents the constraint ‘(InferOverloaded
([a0], [a1]))’ from being solved.
- Probable fix: use a type annotation to specify what ‘a0’, ‘a1’ should be.
- These potential instance exist:
+ Probable fix: use a type annotation to specify what ‘a0’,
+ ‘a1’ should be.
+ This potential instance exists:
instance (t1 ~ String) => InferOverloaded (t1, t1)
-- Defined at T5858.hs:8:10
• In the expression: infer ([], [])
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 8745ea9172..b573f9b7f6 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -633,3 +633,4 @@ test('T19615', normal, compile_fail, [''])
test('T17817', normal, compile_fail, [''])
test('T17817_elab', normal, compile_fail, ['-fprint-typechecker-elaboration'])
test('T19978', normal, compile_fail, [''])
+test('T20122', normal, compile_fail, ['']) \ No newline at end of file
diff --git a/testsuite/tests/typecheck/should_fail/tcfail040.stderr b/testsuite/tests/typecheck/should_fail/tcfail040.stderr
index 6e0da922c5..46e0b86577 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail040.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail040.stderr
@@ -1,10 +1,10 @@
tcfail040.hs:19:5: error:
- Ambiguous type variable ‘a0’ arising from a use of ‘<<’
- prevents the constraint ‘(ORD a0)’ from being solved.
- Probable fix: use a type annotation to specify what ‘a0’ should be.
- These potential instance exist:
- instance ORD (a -> b) -- Defined at tcfail040.hs:17:10
- In the first argument of ‘(===)’, namely ‘(<<)’
- In the expression: (<<) === (<<)
- In an equation for ‘f’: f = (<<) === (<<)
+ • Ambiguous type variable ‘a0’ arising from a use of ‘<<’
+ prevents the constraint ‘(ORD a0)’ from being solved.
+ Probable fix: use a type annotation to specify what ‘a0’ should be.
+ This potential instance exists:
+ instance ORD (a -> b) -- Defined at tcfail040.hs:17:10
+ • In the first argument of ‘(===)’, namely ‘(<<)’
+ In the expression: (<<) === (<<)
+ In an equation for ‘f’: f = (<<) === (<<)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail043.stderr b/testsuite/tests/typecheck/should_fail/tcfail043.stderr
index c30b5bf854..03aef3db67 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail043.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail043.stderr
@@ -1,42 +1,42 @@
tcfail043.hs:38:17: error:
- Ambiguous type variable ‘a0’ arising from a use of ‘gt’
- prevents the constraint ‘(Ord_ a0)’ from being solved.
- Relevant bindings include
- bs :: [a0] (bound at tcfail043.hs:38:8)
- a :: a0 (bound at tcfail043.hs:38:6)
- search :: a0 -> [a0] -> Bool (bound at tcfail043.hs:37:1)
- Probable fix: use a type annotation to specify what ‘a0’ should be.
- These potential instance exist:
- instance Ord_ Int -- Defined at tcfail043.hs:34:10
- In the expression: gt (hd bs) a
- In the expression:
- if gt (hd bs) a then
- False
- else
- if eq a (hd bs) then True else search a (tl bs)
- In the expression:
- \ a bs
- -> if gt (hd bs) a then
- False
- else
- if eq a (hd bs) then True else search a (tl bs)
+ • Ambiguous type variable ‘a0’ arising from a use of ‘gt’
+ prevents the constraint ‘(Ord_ a0)’ from being solved.
+ Relevant bindings include
+ bs :: [a0] (bound at tcfail043.hs:38:8)
+ a :: a0 (bound at tcfail043.hs:38:6)
+ search :: a0 -> [a0] -> Bool (bound at tcfail043.hs:37:1)
+ Probable fix: use a type annotation to specify what ‘a0’ should be.
+ This potential instance exists:
+ instance Ord_ Int -- Defined at tcfail043.hs:34:10
+ • In the expression: gt (hd bs) a
+ In the expression:
+ if gt (hd bs) a then
+ False
+ else
+ if eq a (hd bs) then True else search a (tl bs)
+ In the expression:
+ \ a bs
+ -> if gt (hd bs) a then
+ False
+ else
+ if eq a (hd bs) then True else search a (tl bs)
tcfail043.hs:40:25: error:
- Ambiguous type variable ‘a0’ arising from a use of ‘eq’
- prevents the constraint ‘(Eq_ a0)’ from being solved.
- Relevant bindings include
- bs :: [a0] (bound at tcfail043.hs:38:8)
- a :: a0 (bound at tcfail043.hs:38:6)
- search :: a0 -> [a0] -> Bool (bound at tcfail043.hs:37:1)
- Probable fix: use a type annotation to specify what ‘a0’ should be.
- These potential instances exist:
- instance Eq_ Int -- Defined at tcfail043.hs:20:10
- instance Eq_ a => Eq_ [a] -- Defined at tcfail043.hs:23:10
- In the expression: eq a (hd bs)
- In the expression: if eq a (hd bs) then True else search a (tl bs)
- In the expression:
- if gt (hd bs) a then
- False
- else
- if eq a (hd bs) then True else search a (tl bs)
+ • Ambiguous type variable ‘a0’ arising from a use of ‘eq’
+ prevents the constraint ‘(Eq_ a0)’ from being solved.
+ Relevant bindings include
+ bs :: [a0] (bound at tcfail043.hs:38:8)
+ a :: a0 (bound at tcfail043.hs:38:6)
+ search :: a0 -> [a0] -> Bool (bound at tcfail043.hs:37:1)
+ Probable fix: use a type annotation to specify what ‘a0’ should be.
+ These potential instances exist:
+ instance Eq_ Int -- Defined at tcfail043.hs:20:10
+ instance Eq_ a => Eq_ [a] -- Defined at tcfail043.hs:23:10
+ • In the expression: eq a (hd bs)
+ In the expression: if eq a (hd bs) then True else search a (tl bs)
+ In the expression:
+ if gt (hd bs) a then
+ False
+ else
+ if eq a (hd bs) then True else search a (tl bs)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail128.stderr b/testsuite/tests/typecheck/should_fail/tcfail128.stderr
index d78c46a191..a63f290418 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail128.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail128.stderr
@@ -4,7 +4,7 @@ tcfail128.hs:18:16: error:
prevents the constraint ‘(Data.Array.Base.MArray
b0 FlatVector IO)’ from being solved.
Probable fix: use a type annotation to specify what ‘b0’ should be.
- These potential instance exist:
+ This potential instance exists:
one instance involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of a 'do' block: v <- thaw tmp