summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2023-02-08 11:43:49 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-02-08 14:40:40 -0500
commit9ee761bf02cdd11c955454a222c85971d95dce11 (patch)
treea3f926f08c73a5e2ab4381bb6ed5aac1b633839f /testsuite
parenta9912de75400b7006fc2eb6cb31c9bf5ae6dacd6 (diff)
downloadhaskell-9ee761bf02cdd11c955454a222c85971d95dce11.tar.gz
Fix tyvar scoping within class SPECIALISE pragmas
Type variables from class/instance headers scope over class/instance method type signatures, but DO NOT scope over the type signatures in SPECIALISE and SPECIALISE instance pragmas. The logic in GHC.Rename.Bind.rnMethodBinds correctly accounted for SPECIALISE inline pragmas, but forgot to apply the same treatment to method SPECIALISE pragmas, which lead to a Core Lint failure with an out-of-scope type variable. This patch makes sure we apply the same logic for both cases. Fixes #22913
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/rename/should_compile/T22913.hs10
-rw-r--r--testsuite/tests/rename/should_compile/all.T1
2 files changed, 11 insertions, 0 deletions
diff --git a/testsuite/tests/rename/should_compile/T22913.hs b/testsuite/tests/rename/should_compile/T22913.hs
new file mode 100644
index 0000000000..a43ee28a9d
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T22913.hs
@@ -0,0 +1,10 @@
+module T22913 where
+
+class FromSourceIO a where
+ fromSourceIO :: a
+instance FromSourceIO (Maybe o) where
+ fromSourceIO = undefined
+ {-# SPECIALISE INLINE fromSourceIO :: Maybe o #-}
+ -- This SPECIALISE pragma caused a Core Lint error
+ -- due to incorrectly scoping the type variable 'o' from the instance header
+ -- over the SPECIALISE pragma.
diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T
index 19401582dd..673cdf8c78 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -199,3 +199,4 @@ test('T22513f', normal, compile, ['-Wterm-variable-capture'])
test('T22513g', normal, compile, ['-Wterm-variable-capture'])
test('T22513h', normal, compile, ['-Wterm-variable-capture'])
test('T22513i', req_th, compile, ['-Wterm-variable-capture'])
+test('T22913', normal, compile, [''])