summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2016-10-01 17:55:04 -0400
committerBen Gamari <ben@smart-cactus.org>2016-10-01 20:01:29 -0400
commit2d6642bd1956edf8b842c07d78e83c500246998a (patch)
treec16292ebfe857bba54c65de413c260e576860a46
parentc93813d96b1da53a2ebd9c9ac5af6cc3e3443c43 (diff)
downloadhaskell-2d6642bd1956edf8b842c07d78e83c500246998a.tar.gz
Fix interaction of record pattern synonyms and record wildcards
We were missing an appropiate *ConLike lookup in the case when the pattern synonym was defined in a different module. Reviewers: austin, bgamari, simonpj Reviewed By: simonpj Subscribers: simonpj, thomie Differential Revision: https://phabricator.haskell.org/D2544 GHC Trac Issues: #11987
-rw-r--r--compiler/rename/RnEnv.hs4
-rw-r--r--testsuite/tests/patsyn/should_compile/T11987.hs12
-rw-r--r--testsuite/tests/patsyn/should_compile/T11987a.hs9
-rw-r--r--testsuite/tests/patsyn/should_compile/all.T3
4 files changed, 25 insertions, 3 deletions
diff --git a/compiler/rename/RnEnv.hs b/compiler/rename/RnEnv.hs
index 63b1f1f102..37e389e547 100644
--- a/compiler/rename/RnEnv.hs
+++ b/compiler/rename/RnEnv.hs
@@ -462,9 +462,9 @@ lookupConstructorFields con_name
; traceTc "lookupCF" (ppr con_name $$ ppr (lookupNameEnv field_env con_name) $$ ppr field_env)
; return (lookupNameEnv field_env con_name `orElse` []) }
else
- do { con <- tcLookupDataCon con_name
+ do { con <- tcLookupConLike con_name
; traceTc "lookupCF 2" (ppr con)
- ; return (dataConFieldLabels con) } }
+ ; return (conLikeFieldLabels con) } }
-----------------------------------------------
-- Used for record construction and pattern matching
diff --git a/testsuite/tests/patsyn/should_compile/T11987.hs b/testsuite/tests/patsyn/should_compile/T11987.hs
new file mode 100644
index 0000000000..eab3316b2a
--- /dev/null
+++ b/testsuite/tests/patsyn/should_compile/T11987.hs
@@ -0,0 +1,12 @@
+{-# LANGUAGE NamedFieldPuns, PatternSynonyms, RecordWildCards #-}
+module T11987 where
+
+import T11987a
+
+-- works
+namedFieldPuns :: (Int,Int)
+namedFieldPuns = let { x = 1; y = 2 } in Point { x, y }
+
+-- error: Pattern synonym ‘Point’ used as a data constructor
+recordWildCards :: (Int,Int)
+recordWildCards = let { x = 1; y = 2 } in Point { .. }
diff --git a/testsuite/tests/patsyn/should_compile/T11987a.hs b/testsuite/tests/patsyn/should_compile/T11987a.hs
new file mode 100644
index 0000000000..c381c2b35d
--- /dev/null
+++ b/testsuite/tests/patsyn/should_compile/T11987a.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE NamedFieldPuns, PatternSynonyms, RecordWildCards #-}
+module T11987a where
+
+pattern Point :: Int -> Int -> (Int, Int)
+pattern Point{x, y} = (x, y)
+
+-- works
+sameFile :: (Int,Int)
+sameFile = let { x = 1; y = 2 } in Point { .. }
diff --git a/testsuite/tests/patsyn/should_compile/all.T b/testsuite/tests/patsyn/should_compile/all.T
index 7551eb91dd..1297d8cd1a 100644
--- a/testsuite/tests/patsyn/should_compile/all.T
+++ b/testsuite/tests/patsyn/should_compile/all.T
@@ -58,4 +58,5 @@ test('T12094', normal, compile, [''])
test('T11977', normal, compile, [''])
test('T12108', normal, compile, [''])
test('T12484', normal, compile, [''])
-test('T12489', normal, compile, [''])
+test('T11987', normal, multimod_compile, ['T11987', '-v0'])
+