diff options
author | Jakob Brünker <jakob.bruenker@gmail.com> | 2021-05-16 07:09:58 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-05-21 06:22:47 -0400 |
commit | d9eb8bbf38cda5b6c885fad8ae8addea3325ce42 (patch) | |
tree | a7eaa0e7ce587e6d8037667fb28367f3e830e9db /testsuite/tests/rename | |
parent | 703c0c3c13cad700ae998de062134119bd33071f (diff) | |
download | haskell-d9eb8bbf38cda5b6c885fad8ae8addea3325ce42.tar.gz |
Only suggest names that make sense (#19843)
* Don't show suggestions for similar variables when a data constructor
in a pattern is not in scope.
* Only suggest record fields when a record field for record creation or
updating is not in scope.
* Suggest similar record fields when a record field is not in scope with
-XOverloadedRecordDot.
* Show suggestions for data constructors if a type constructor or type
is not in scope, but only if -XDataKinds is enabled.
Fixes #19843.
Diffstat (limited to 'testsuite/tests/rename')
29 files changed, 213 insertions, 3 deletions
diff --git a/testsuite/tests/rename/should_fail/T19843a.hs b/testsuite/tests/rename/should_fail/T19843a.hs new file mode 100644 index 0000000000..746357d3e8 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843a.hs @@ -0,0 +1,5 @@ +module T19843a where + +import Prelude (map, undefined) + +foo (Map k v) = undefined diff --git a/testsuite/tests/rename/should_fail/T19843a.stderr b/testsuite/tests/rename/should_fail/T19843a.stderr new file mode 100644 index 0000000000..8f96612743 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843a.stderr @@ -0,0 +1,3 @@ + +T19843a.hs:5:6: + Not in scope: data constructor ‘Map’ diff --git a/testsuite/tests/rename/should_fail/T19843b.hs b/testsuite/tests/rename/should_fail/T19843b.hs new file mode 100644 index 0000000000..4bd6ef2d1b --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843b.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE ViewPatterns #-} + +module T19843b where + +import Prelude (map, even, undefined, Bool) + +foo (Map even -> xs) = undefined diff --git a/testsuite/tests/rename/should_fail/T19843b.stderr b/testsuite/tests/rename/should_fail/T19843b.stderr new file mode 100644 index 0000000000..5b457440eb --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843b.stderr @@ -0,0 +1,4 @@ + +T19843b.hs:7:6: + • Data constructor not in scope: Map :: (a0 -> Bool) -> t -> t0 + • Perhaps you meant variable ‘map’ (imported from Prelude) diff --git a/testsuite/tests/rename/should_fail/T19843c.hs b/testsuite/tests/rename/should_fail/T19843c.hs new file mode 100644 index 0000000000..1b55bce68b --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843c.hs @@ -0,0 +1,6 @@ +module T19843c where + +import Data.Map as Map +import Prelude (undefined, map) + +foo (Map.Map k v) = undefined diff --git a/testsuite/tests/rename/should_fail/T19843c.stderr b/testsuite/tests/rename/should_fail/T19843c.stderr new file mode 100644 index 0000000000..94cdadf528 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843c.stderr @@ -0,0 +1,4 @@ + +T19843c.hs:6:6: error: + Not in scope: data constructor ‘Map.Map’ + Module ‘Data.Map’ does not export ‘Map’. diff --git a/testsuite/tests/rename/should_fail/T19843d.hs b/testsuite/tests/rename/should_fail/T19843d.hs new file mode 100644 index 0000000000..72ddc65f3a --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843d.hs @@ -0,0 +1,7 @@ +module T19843d where + +import Prelude (undefined, map) + +data Mup k v = Mup k v + +foo (Map k v) = undefined diff --git a/testsuite/tests/rename/should_fail/T19843d.stderr b/testsuite/tests/rename/should_fail/T19843d.stderr new file mode 100644 index 0000000000..a27a627005 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843d.stderr @@ -0,0 +1,4 @@ + +T19843d.hs:7:6: error: + Not in scope: data constructor ‘Map’ + Perhaps you meant ‘Mup’ (line 5) diff --git a/testsuite/tests/rename/should_fail/T19843e.hs b/testsuite/tests/rename/should_fail/T19843e.hs new file mode 100644 index 0000000000..9223f6e169 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843e.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE PatternSynonyms #-} + +module T19843e where + +import Prelude (undefined, map, Maybe(Just)) + +pattern Mup k = Just k + +foo (Map k) = undefined diff --git a/testsuite/tests/rename/should_fail/T19843e.stderr b/testsuite/tests/rename/should_fail/T19843e.stderr new file mode 100644 index 0000000000..890c719bd8 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843e.stderr @@ -0,0 +1,4 @@ + +T19843e.hs:9:6: error: + Not in scope: data constructor ‘Map’ + Perhaps you meant ‘Mup’ (line 7) diff --git a/testsuite/tests/rename/should_fail/T19843f.hs b/testsuite/tests/rename/should_fail/T19843f.hs new file mode 100644 index 0000000000..64beb233fa --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843f.hs @@ -0,0 +1,10 @@ +module T19843f where + +import Prelude (Int, map) + +data A = A {mop :: ()} +data Mup = Mup + +foo = foo {mup = 1} + +bar = A {mup = 1} diff --git a/testsuite/tests/rename/should_fail/T19843f.stderr b/testsuite/tests/rename/should_fail/T19843f.stderr new file mode 100644 index 0000000000..903fee7849 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843f.stderr @@ -0,0 +1,8 @@ + +T19843f.hs:8:12: error: + Not in scope: ‘mup’ + Perhaps you meant ‘mop’ (line 5) + +T19843f.hs:10:10: error: + Not in scope: ‘mup’ + Perhaps you meant ‘mop’ (line 5) diff --git a/testsuite/tests/rename/should_fail/T19843g.hs b/testsuite/tests/rename/should_fail/T19843g.hs new file mode 100644 index 0000000000..22db3381f3 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843g.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE NoFieldSelectors #-} + +module T19843g where + +import Prelude (Int, map) + +data A = A {mop :: ()} +data Mup = Mup + +foo = foo {mup = 1} diff --git a/testsuite/tests/rename/should_fail/T19843g.stderr b/testsuite/tests/rename/should_fail/T19843g.stderr new file mode 100644 index 0000000000..6d0d398bfd --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843g.stderr @@ -0,0 +1,4 @@ + +T19843g.hs:10:12: error: + Not in scope: ‘mup’ + Perhaps you meant ‘mop’ (line 7) diff --git a/testsuite/tests/rename/should_fail/T19843h.hs b/testsuite/tests/rename/should_fail/T19843h.hs new file mode 100644 index 0000000000..d78418555f --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843h.hs @@ -0,0 +1,24 @@ +{-# LANGUAGE NoFieldSelectors #-} +{-# LANGUAGE OverloadedRecordDot #-} + +module T19843h where + +import Prelude (Int, map, undefined) +import Data.Traversable hiding (traverse) +import qualified Data.Monoid (Sum(..), getSum) +import Data.Monoid (Alt(..)) + +data A = A {mop :: ()} +data Mup = Mup + +foo = undefined.mup + +bar = undefined.traverse + +baz = undefined.getSum + +quux = undefined.getAlt + +quuz = getAlt undefined + +quur = undefined.getAll diff --git a/testsuite/tests/rename/should_fail/T19843h.stderr b/testsuite/tests/rename/should_fail/T19843h.stderr new file mode 100644 index 0000000000..56bca0feeb --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843h.stderr @@ -0,0 +1,34 @@ + +T19843h.hs:14:7: + No instance for (GHC.Records.HasField "mup" r4 a4) + arising from selecting the field ‘mup’ + Perhaps you meant ‘mop’ (line 11) + In the expression: undefined.mup + In an equation for ‘foo’: foo = undefined.mup + +T19843h.hs:16:7: + No instance for (GHC.Records.HasField "traverse" r3 a3) + arising from selecting the field ‘traverse’ + In the expression: undefined.traverse + In an equation for ‘bar’: bar = undefined.traverse + +T19843h.hs:18:7: + No instance for (GHC.Records.HasField "getSum" r2 a2) + arising from selecting the field ‘getSum’ + In the expression: undefined.getSum + In an equation for ‘baz’: baz = undefined.getSum + +T19843h.hs:20:8: + No instance for (GHC.Records.HasField "getAlt" r1 a1) + arising from selecting the field ‘getAlt’ + In the expression: undefined.getAlt + In an equation for ‘quux’: quux = undefined.getAlt + +T19843h.hs:24:8: + No instance for (GHC.Records.HasField "getAll" r0 a0) + arising from selecting the field ‘getAll’ + Perhaps you meant ‘getAlt’ (imported from Data.Monoid) + Perhaps you want to add ‘getAll’ to the import list + in the import of ‘Data.Monoid’ (T19843h.hs:9:1-28). + In the expression: undefined.getAll + In an equation for ‘quur’: quur = undefined.getAll diff --git a/testsuite/tests/rename/should_fail/T19843i.hs b/testsuite/tests/rename/should_fail/T19843i.hs new file mode 100644 index 0000000000..5ed9668577 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843i.hs @@ -0,0 +1,5 @@ +module T19843i where + +import Data.Monoid as M (getAll) + +x = M.getSum diff --git a/testsuite/tests/rename/should_fail/T19843i.stderr b/testsuite/tests/rename/should_fail/T19843i.stderr new file mode 100644 index 0000000000..60f671c679 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843i.stderr @@ -0,0 +1,5 @@ + +T19843i.hs:5:5: + Not in scope: ‘M.getSum’ + Perhaps you want to add ‘getSum’ to the import list + in the import of ‘Data.Monoid’ (T19843i.hs:3:1-32). diff --git a/testsuite/tests/rename/should_fail/T19843j.hs b/testsuite/tests/rename/should_fail/T19843j.hs new file mode 100644 index 0000000000..20cd1c84d8 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843j.hs @@ -0,0 +1,5 @@ +module T19843j where + +import Control.Monad (sequence) + +x = guard diff --git a/testsuite/tests/rename/should_fail/T19843j.stderr b/testsuite/tests/rename/should_fail/T19843j.stderr new file mode 100644 index 0000000000..e99a9f0a62 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843j.stderr @@ -0,0 +1,5 @@ + +T19843j.hs:5:5: + Variable not in scope: guard + Perhaps you want to add ‘guard’ to the import list + in the import of ‘Control.Monad’ (T19843j.hs:3:1-31). diff --git a/testsuite/tests/rename/should_fail/T19843k.hs b/testsuite/tests/rename/should_fail/T19843k.hs new file mode 100644 index 0000000000..d97819b306 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843k.hs @@ -0,0 +1,5 @@ +module T19843k where + +import Data.Monoid as M + +main = M.doesn'tExist diff --git a/testsuite/tests/rename/should_fail/T19843k.stderr b/testsuite/tests/rename/should_fail/T19843k.stderr new file mode 100644 index 0000000000..08ed7d8c08 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843k.stderr @@ -0,0 +1,4 @@ + +T19843k.hs:5:8: + Not in scope: ‘M.doesn'tExist’ + Module ‘Data.Monoid’ does not export ‘doesn'tExist’. diff --git a/testsuite/tests/rename/should_fail/T19843l.hs b/testsuite/tests/rename/should_fail/T19843l.hs new file mode 100644 index 0000000000..340fe68539 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843l.hs @@ -0,0 +1,7 @@ +module T19843l where + +data Foo = LongName +data FongName +wrongName = wrongName + +type Bar = WrongName diff --git a/testsuite/tests/rename/should_fail/T19843l.stderr b/testsuite/tests/rename/should_fail/T19843l.stderr new file mode 100644 index 0000000000..d5168b2b90 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843l.stderr @@ -0,0 +1,4 @@ + +T19843l.hs:7:12: + Not in scope: type constructor or class ‘WrongName’ + Perhaps you meant ‘FongName’ (line 4) diff --git a/testsuite/tests/rename/should_fail/T19843m.hs b/testsuite/tests/rename/should_fail/T19843m.hs new file mode 100644 index 0000000000..72c08b2fdd --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843m.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE DataKinds #-} + +module T19843m where + +data Foo = LongName +data FongName +wrongName = wrongName + +type Bar = WrongName diff --git a/testsuite/tests/rename/should_fail/T19843m.stderr b/testsuite/tests/rename/should_fail/T19843m.stderr new file mode 100644 index 0000000000..dd7583842a --- /dev/null +++ b/testsuite/tests/rename/should_fail/T19843m.stderr @@ -0,0 +1,5 @@ + +T19843m.hs:9:12: + Not in scope: type constructor or class ‘WrongName’ + Perhaps you meant one of these: + ‘FongName’ (line 6), data constructor ‘LongName’ (line 5) diff --git a/testsuite/tests/rename/should_fail/T9177.hs b/testsuite/tests/rename/should_fail/T9177.hs index 553dbc7b53..2554e90a65 100644 --- a/testsuite/tests/rename/should_fail/T9177.hs +++ b/testsuite/tests/rename/should_fail/T9177.hs @@ -12,7 +12,8 @@ type Foo2 = (integerr) foo3 = bar foo4 = Fun --- this warning is suboptimal (fun would be illegal here) +-- this warning was suboptimal (fun would be illegal here) as of #9177 +-- fixed with #19843 foo5 Fun = () -- No errors here: diff --git a/testsuite/tests/rename/should_fail/T9177.stderr b/testsuite/tests/rename/should_fail/T9177.stderr index b336b32524..a1153b4fcb 100644 --- a/testsuite/tests/rename/should_fail/T9177.stderr +++ b/testsuite/tests/rename/should_fail/T9177.stderr @@ -7,6 +7,5 @@ T9177.hs:7:14: error: Not in scope: type variable ‘integerr’ Perhaps you meant type constructor or class ‘Integer’ (imported from Prelude) -T9177.hs:16:6: error: +T9177.hs:17:6: error: Not in scope: data constructor ‘Fun’ - Perhaps you meant variable ‘fun’ (line 20) diff --git a/testsuite/tests/rename/should_fail/all.T b/testsuite/tests/rename/should_fail/all.T index a5dd61e575..d709fd0ad0 100644 --- a/testsuite/tests/rename/should_fail/all.T +++ b/testsuite/tests/rename/should_fail/all.T @@ -165,3 +165,16 @@ test('T18240b', normal, compile_fail, ['']) test('T18740a', normal, compile_fail, ['']) test('T18740b', normal, compile_fail, ['']) test('T19781', [extra_files(['T19781_A.hs', 'T19781_A.hs-boot'])], multimod_compile_fail, ['T19781', '-v0']) +test('T19843a', normal, compile_fail, ['']) +test('T19843b', normal, compile_fail, ['']) +test('T19843c', normal, compile_fail, ['']) +test('T19843d', normal, compile_fail, ['']) +test('T19843e', normal, compile_fail, ['']) +test('T19843f', normal, compile_fail, ['']) +test('T19843g', normal, compile_fail, ['']) +test('T19843h', normal, compile_fail, ['']) +test('T19843i', normal, compile_fail, ['']) +test('T19843j', normal, compile_fail, ['']) +test('T19843k', normal, compile_fail, ['']) +test('T19843l', normal, compile_fail, ['']) +test('T19843m', normal, compile_fail, ['']) |