summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2021-02-02 10:36:57 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-02-06 09:27:28 -0500
commit18313374e42925d1c7a8684b52e922689610574f (patch)
tree19998a8c6a046215e303a592fd612e519499b5e3
parent7f3524efcbd58ca6837ec0ffca6ddd121d64e4de (diff)
downloadhaskell-18313374e42925d1c7a8684b52e922689610574f.tar.gz
Fix buglet in expandSynTyCon_maybe
The fix for #17958, implemented in MR !2952, introduced a small bug in GHC.Core.TyCon.expandSynTyCon_maybe, in the case of under-saturated type synonyms. This MR fixes the bug, very easy. Fixes #19279
-rw-r--r--compiler/GHC/Core/TyCon.hs11
-rw-r--r--testsuite/tests/ghci/scripts/T19279.script3
-rw-r--r--testsuite/tests/ghci/scripts/T19279.stdout3
-rwxr-xr-xtestsuite/tests/ghci/scripts/all.T1
4 files changed, 13 insertions, 5 deletions
diff --git a/compiler/GHC/Core/TyCon.hs b/compiler/GHC/Core/TyCon.hs
index 4db3167bd7..efa6cfbcf7 100644
--- a/compiler/GHC/Core/TyCon.hs
+++ b/compiler/GHC/Core/TyCon.hs
@@ -2257,13 +2257,14 @@ expandSynTyCon_maybe
-- type of the synonym (not yet substituted)
-- and any arguments remaining from the
-- application
-
--- ^ Expand a type synonym application, if any
+-- ^ Expand a type synonym application
+-- Return Nothing if the TyCon is not a synonym,
+-- or if not enough arguments are supplied
expandSynTyCon_maybe tc tys
| SynonymTyCon { tyConTyVars = tvs, synTcRhs = rhs, tyConArity = arity } <- tc
- = case tys of
- [] -> Just ([], rhs, []) -- Avoid a bit of work in the case of nullary synonyms
- _ -> case tys `listLengthCmp` arity of
+ = if arity == 0
+ then Just ([], rhs, tys) -- Avoid a bit of work in the case of nullary synonyms
+ else case tys `listLengthCmp` arity of
GT -> Just (tvs `zip` tys, rhs, drop arity tys)
EQ -> Just (tvs `zip` tys, rhs, [])
LT -> Nothing
diff --git a/testsuite/tests/ghci/scripts/T19279.script b/testsuite/tests/ghci/scripts/T19279.script
new file mode 100644
index 0000000000..b414e1dc8b
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T19279.script
@@ -0,0 +1,3 @@
+type T a = a
+:kind! T
+:kind T
diff --git a/testsuite/tests/ghci/scripts/T19279.stdout b/testsuite/tests/ghci/scripts/T19279.stdout
new file mode 100644
index 0000000000..fe7fbbf9f8
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T19279.stdout
@@ -0,0 +1,3 @@
+T :: * -> *
+= T
+T :: * -> *
diff --git a/testsuite/tests/ghci/scripts/all.T b/testsuite/tests/ghci/scripts/all.T
index 08a6c4ee6a..a85fe27fd3 100755
--- a/testsuite/tests/ghci/scripts/all.T
+++ b/testsuite/tests/ghci/scripts/all.T
@@ -328,4 +328,5 @@ test('T18755', normal, ghci_script, ['T18755.script'])
test('T18828', normal, ghci_script, ['T18828.script'])
test('T19197', normal, ghci_script, ['T19197.script'])
test('T19158', normal, ghci_script, ['T19158.script'])
+test('T19279', normal, ghci_script, ['T19279.script'])