summaryrefslogtreecommitdiff
path: root/testsuite/tests/overloadedrecflds
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2021-07-27 18:07:11 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-02-04 20:36:20 -0500
commit6af8e71ed7e749ba94e7a7eaf8b2229341bf35da (patch)
treeaabf6c233d2067ca9f62b5c5ff4ec83576e58bd9 /testsuite/tests/overloadedrecflds
parentbf495f7206741c81135c04ce6bb943c4a6729e80 (diff)
downloadhaskell-6af8e71ed7e749ba94e7a7eaf8b2229341bf35da.tar.gz
Improve errors for non-existent labels
This patch fixes #17469, by improving matters when you use non-existent field names in a record construction: data T = MkT { x :: Int } f v = MkT { y = 3 } The check is now made in the renamer, in GHC.Rename.Env.lookupRecFieldOcc. That in turn led to a spurious error in T9975a, which is fixed by making GHC.Rename.Names.extendGlobalRdrEnvRn fail fast if it finds duplicate bindings. See Note [Fail fast on duplicate definitions] in that module for more details. This patch was originated and worked on by Alex D (@nineonine)
Diffstat (limited to 'testsuite/tests/overloadedrecflds')
-rw-r--r--testsuite/tests/overloadedrecflds/should_fail/T17469.hs6
-rw-r--r--testsuite/tests/overloadedrecflds/should_fail/T17469.stderr5
-rw-r--r--testsuite/tests/overloadedrecflds/should_fail/T17469A.hs9
-rw-r--r--testsuite/tests/overloadedrecflds/should_fail/all.T2
4 files changed, 22 insertions, 0 deletions
diff --git a/testsuite/tests/overloadedrecflds/should_fail/T17469.hs b/testsuite/tests/overloadedrecflds/should_fail/T17469.hs
new file mode 100644
index 0000000000..319f4d873d
--- /dev/null
+++ b/testsuite/tests/overloadedrecflds/should_fail/T17469.hs
@@ -0,0 +1,6 @@
+{-# LANGUAGE DuplicateRecordFields #-}
+
+import T17469A
+
+main :: IO ()
+main = print MkFoo { foo = "", bar = True }
diff --git a/testsuite/tests/overloadedrecflds/should_fail/T17469.stderr b/testsuite/tests/overloadedrecflds/should_fail/T17469.stderr
new file mode 100644
index 0000000000..5d93f46489
--- /dev/null
+++ b/testsuite/tests/overloadedrecflds/should_fail/T17469.stderr
@@ -0,0 +1,5 @@
+[1 of 3] Compiling T17469A ( T17469A.hs, T17469A.o )
+[2 of 3] Compiling Main ( T17469.hs, T17469.o )
+
+T17469.hs:6:32: error:
+ Constructor ‘MkFoo’ does not have field ‘bar’
diff --git a/testsuite/tests/overloadedrecflds/should_fail/T17469A.hs b/testsuite/tests/overloadedrecflds/should_fail/T17469A.hs
new file mode 100644
index 0000000000..da0d8eb827
--- /dev/null
+++ b/testsuite/tests/overloadedrecflds/should_fail/T17469A.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE DuplicateRecordFields #-}
+
+module T17469A where
+
+data Foo = MkFoo { foo :: String } deriving Show
+
+data FooWithBar = MkFooWithBar { foo :: String, bar :: Bool } deriving Show
+
+data FooWithBarAndBaz = MkFooWithBarAndBaz { foo :: String, bar :: Bool, baz :: Int } deriving Show
diff --git a/testsuite/tests/overloadedrecflds/should_fail/all.T b/testsuite/tests/overloadedrecflds/should_fail/all.T
index 396ea516e8..b6729376cb 100644
--- a/testsuite/tests/overloadedrecflds/should_fail/all.T
+++ b/testsuite/tests/overloadedrecflds/should_fail/all.T
@@ -32,6 +32,8 @@ test('hasfieldfail03', normal, compile_fail, [''])
test('T14953', [extra_files(['T14953_A.hs', 'T14953_B.hs'])],
multimod_compile_fail, ['T14953', ''])
test('DuplicateExports', normal, compile_fail, [''])
+test('T17469', [extra_files(['T17469A.hs'])], multimod_compile_fail,
+ ['T17469', ''])
test('T17965', normal, compile_fail, [''])
test('DRFHoleFits', extra_files(['DRFHoleFits_A.hs']), multimod_compile_fail, ['DRFHoleFits', ''])
test('DRFPartialFields', normal, compile_fail, [''])