diff options
author | sheaf <sam.derbyshire@gmail.com> | 2022-01-04 12:59:47 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-01-04 19:56:13 -0500 |
commit | 5111028ee0910305d94671397b8ccc5b60ed296b (patch) | |
tree | fa334ff1dc59669eae86abeb5a03102efc14628d /testsuite/tests | |
parent | 7f10686e61e49c89baf45df92eb24ad3504492f7 (diff) | |
download | haskell-5111028ee0910305d94671397b8ccc5b60ed296b.tar.gz |
Check quoted TH names are in the correct namespace
When quoting (using a TH single or double quote) a built-in
name such as the list constructor (:), we didn't always check
that the resulting 'Name' was in the correct namespace.
This patch adds a check in GHC.Rename.Splice to ensure
we get a Name that is in the term-level/type-level namespace,
when using a single/double tick, respectively.
Fixes #20884.
Diffstat (limited to 'testsuite/tests')
-rw-r--r-- | testsuite/tests/module/mod132.stderr | 8 | ||||
-rw-r--r-- | testsuite/tests/module/mod147.stderr | 10 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/RnStaticPointersFail02.stderr | 12 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/T18740a.stderr | 6 | ||||
-rw-r--r-- | testsuite/tests/th/T14627.stderr | 12 | ||||
-rw-r--r-- | testsuite/tests/th/T20884.hs | 12 | ||||
-rw-r--r-- | testsuite/tests/th/T20884.stderr | 7 | ||||
-rw-r--r-- | testsuite/tests/th/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T19978.stderr | 12 |
9 files changed, 50 insertions, 30 deletions
diff --git a/testsuite/tests/module/mod132.stderr b/testsuite/tests/module/mod132.stderr index 31d9c8eeb6..0c901d090c 100644 --- a/testsuite/tests/module/mod132.stderr +++ b/testsuite/tests/module/mod132.stderr @@ -1,8 +1,8 @@ mod132.hs:6:7: error: - • Illegal term-level use of the type constructor ‘Foo’ - imported from ‘Mod132_B’ at mod132.hs:4:1-15 - (and originally defined in ‘Mod132_A’ at Mod132_A.hs:3:1-14) - Perhaps you meant variable ‘foo’ (line 6) + • Illegal term-level use of the type constructor or class ‘Foo’ + • imported from ‘Mod132_B’ at mod132.hs:4:1-15 + (and originally defined in ‘Mod132_A’ at Mod132_A.hs:3:1-14) + • Perhaps you meant variable ‘foo’ (line 6) • In the expression: Foo In an equation for ‘foo’: foo = Foo diff --git a/testsuite/tests/module/mod147.stderr b/testsuite/tests/module/mod147.stderr index 80267f8f24..5500abc5bd 100644 --- a/testsuite/tests/module/mod147.stderr +++ b/testsuite/tests/module/mod147.stderr @@ -1,7 +1,7 @@ -mod147.hs:6:5: - Illegal term-level use of the type constructor ‘D’ - imported from ‘Mod147_A’ at mod147.hs:4:1-15 - (and originally defined at Mod147_A.hs:3:1-14) - In the expression: D 4 +mod147.hs:6:5: error: + • Illegal term-level use of the type constructor or class ‘D’ + • imported from ‘Mod147_A’ at mod147.hs:4:1-15 + (and originally defined at Mod147_A.hs:3:1-14) + • In the expression: D 4 In an equation for ‘x’: x = D 4 diff --git a/testsuite/tests/rename/should_fail/RnStaticPointersFail02.stderr b/testsuite/tests/rename/should_fail/RnStaticPointersFail02.stderr index 8beac36a43..6367162c68 100644 --- a/testsuite/tests/rename/should_fail/RnStaticPointersFail02.stderr +++ b/testsuite/tests/rename/should_fail/RnStaticPointersFail02.stderr @@ -1,7 +1,7 @@ -RnStaticPointersFail02.hs:5:12: -Illegal term-level use of the type constructor ‘T’ - defined at RnStaticPointersFail02.hs:7:1 -In the body of a static form: T - In the expression: static T - In an equation for ‘f’: f = static T +RnStaticPointersFail02.hs:5:12: error: + • Illegal term-level use of the type constructor or class ‘T’ + • defined at RnStaticPointersFail02.hs:7:1 + • In the body of a static form: T + In the expression: static T + In an equation for ‘f’: f = static T diff --git a/testsuite/tests/rename/should_fail/T18740a.stderr b/testsuite/tests/rename/should_fail/T18740a.stderr index 2a0463adf0..c814f2bf36 100644 --- a/testsuite/tests/rename/should_fail/T18740a.stderr +++ b/testsuite/tests/rename/should_fail/T18740a.stderr @@ -1,7 +1,7 @@ T18740a.hs:3:5: error: - • Illegal term-level use of the type constructor ‘Int’ - imported from ‘Prelude’ at T18740a.hs:1:8-14 - (and originally defined in ‘GHC.Types’) + • Illegal term-level use of the type constructor or class ‘Int’ + • imported from ‘Prelude’ at T18740a.hs:1:8-14 + (and originally defined in ‘GHC.Types’) • In the expression: Int In an equation for ‘x’: x = Int diff --git a/testsuite/tests/th/T14627.stderr b/testsuite/tests/th/T14627.stderr index e9e8486256..9d9b9785f0 100644 --- a/testsuite/tests/th/T14627.stderr +++ b/testsuite/tests/th/T14627.stderr @@ -1,7 +1,7 @@ -T14627.hs:4:1: -Illegal term-level use of the type constructor ‘Bool’ - imported from ‘Prelude’ at T14627.hs:1:1 - (and originally defined in ‘GHC.Types’) -In the expression: Bool - In an equation for ‘f’: f = Bool +T14627.hs:4:1: error: + • Illegal term-level use of the type constructor or class ‘Bool’ + • imported from ‘Prelude’ at T14627.hs:1:1 + (and originally defined in ‘GHC.Types’) + • In the expression: Bool + In an equation for ‘f’: f = Bool diff --git a/testsuite/tests/th/T20884.hs b/testsuite/tests/th/T20884.hs new file mode 100644 index 0000000000..0901cd1808 --- /dev/null +++ b/testsuite/tests/th/T20884.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE TemplateHaskell #-} + +module T20884 where + +import Language.Haskell.TH + +list1 = $( conE '(:) `appE` litE (IntegerL 5) `appE` conE '[] ) + -- OK + +list2 = $( conE ''(:) `appE` litE (IntegerL 5) `appE` conE '[] ) + -- should fail because we are trying to quote a type named (:), + -- but (:) is not in the type namespace. diff --git a/testsuite/tests/th/T20884.stderr b/testsuite/tests/th/T20884.stderr new file mode 100644 index 0000000000..20c1c34fd1 --- /dev/null +++ b/testsuite/tests/th/T20884.stderr @@ -0,0 +1,7 @@ + +T20884.hs:10:17: error: + • The data constructor ‘:’ does not live in the type-level namespace + • In the Template Haskell quotation ''(:) + In the untyped splice: + $(conE ''(:) `appE` litE (IntegerL 5) `appE` conE '[]) + Suggested fix: Perhaps use a single tick diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T index cfd40a40df..b04f9cae85 100644 --- a/testsuite/tests/th/all.T +++ b/testsuite/tests/th/all.T @@ -539,3 +539,4 @@ test('T17820d', normal, compile_fail, ['']) test('T17820e', normal, compile_fail, ['']) test('T20590', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques']) test('T20773', only_ways(['ghci']), ghci_script, ['T20773.script']) +test('T20884', normal, compile_fail, ['']) diff --git a/testsuite/tests/typecheck/should_fail/T19978.stderr b/testsuite/tests/typecheck/should_fail/T19978.stderr index 7f41c37ad4..4ea25fcf04 100644 --- a/testsuite/tests/typecheck/should_fail/T19978.stderr +++ b/testsuite/tests/typecheck/should_fail/T19978.stderr @@ -1,9 +1,9 @@ T19978.hs:8:7: error: - • Illegal term-level use of the type constructor ‘Bool’ - imported from ‘Prelude’ at T19978.hs:3:8-13 - (and originally defined in ‘GHC.Types’) - Perhaps you meant one of these: + • Illegal term-level use of the type constructor or class ‘Bool’ + • imported from ‘Prelude’ at T19978.hs:3:8-13 + (and originally defined in ‘GHC.Types’) + • Perhaps you meant one of these: ‘Bowl’ (line 11), variable ‘bool’ (line 12) • In the expression: Bool In an equation for ‘ex1’: ex1 = Bool @@ -14,8 +14,8 @@ T19978.hs:14:7: error: T19978.hs:21:7: error: • Illegal term-level use of the type variable ‘mytv’ - bound at T19978.hs:20:15 - Perhaps you meant one of these: + • bound at T19978.hs:20:15 + • Perhaps you meant one of these: data constructor ‘Mytv’ (line 24), ‘myvv’ (line 25) • In the expression: mytv In an equation for ‘ex3’: ex3 = mytv |