summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_fail
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2023-03-17 12:48:21 +0100
committersheaf <sam.derbyshire@gmail.com>2023-03-29 13:57:33 +0200
commit3f374399e2dbebcdfe5bc31f94fc502b46d0cf4f (patch)
treea5103e3d597c2d724173e070a22759ce50a9d2e7 /testsuite/tests/typecheck/should_fail
parent76bb4c586084d7fdcf0e5ce52623abbfca527c55 (diff)
downloadhaskell-3f374399e2dbebcdfe5bc31f94fc502b46d0cf4f.tar.gz
Handle records in the renamer
This patch moves the field-based logic for disambiguating record updates to the renamer. The type-directed logic, scheduled for removal, remains in the typechecker. To do this properly (and fix the myriad of bugs surrounding the treatment of duplicate record fields), we took the following main steps: 1. Create GREInfo, a renamer-level equivalent to TyThing which stores information pertinent to the renamer. This allows us to uniformly treat imported and local Names in the renamer, as described in Note [GREInfo]. 2. Remove GreName. Instead of a GlobalRdrElt storing GreNames, which distinguished between normal names and field names, we now store simple Names in GlobalRdrElt, along with the new GREInfo information which allows us to recover the FieldLabel for record fields. 3. Add namespacing for record fields, within the OccNames themselves. This allows us to remove the mangling of duplicate field selectors. This change ensures we don't print mangled names to the user in error messages, and allows us to handle duplicate record fields in Template Haskell. 4. Move record disambiguation to the renamer, and operate on the level of data constructors instead, to handle #21443. The error message text for ambiguous record updates has also been changed to reflect that type-directed disambiguation is on the way out. (3) means that OccEnv is now a bit more complex: we first key on the textual name, which gives an inner map keyed on NameSpace: OccEnv a ~ FastStringEnv (UniqFM NameSpace a) Note that this change, along with (2), both increase the memory residency of GlobalRdrEnv = OccEnv [GlobalRdrElt], which causes a few tests to regress somewhat in compile-time allocation. Even though (3) simplified a lot of code (in particular the treatment of field selectors within Template Haskell and in error messages), it came with one important wrinkle: in the situation of -- M.hs-boot module M where { data A; foo :: A -> Int } -- M.hs module M where { data A = MkA { foo :: Int } } we have that M.hs-boot exports a variable foo, which is supposed to match with the record field foo that M exports. To solve this issue, we add a new impedance-matching binding to M foo{var} = foo{fld} This mimics the logic that existed already for impedance-binding DFunIds, but getting it right was a bit tricky. See Note [Record field impedance matching] in GHC.Tc.Module. We also needed to be careful to avoid introducing space leaks in GHCi. So we dehydrate the GlobalRdrEnv before storing it anywhere, e.g. in ModIface. This means stubbing out all the GREInfo fields, with the function forceGlobalRdrEnv. When we read it back in, we rehydrate with rehydrateGlobalRdrEnv. This robustly avoids any space leaks caused by retaining old type environments. Fixes #13352 #14848 #17381 #17551 #19664 #21443 #21444 #21720 #21898 #21946 #21959 #22125 #22160 #23010 #23062 #23063 Updates haddock submodule ------------------------- Metric Increase: MultiComponentModules MultiLayerModules MultiLayerModulesDefsGhci MultiLayerModulesNoCode T13701 T14697 hard_hole_fits -------------------------
Diffstat (limited to 'testsuite/tests/typecheck/should_fail')
-rw-r--r--testsuite/tests/typecheck/should_fail/T12035.hs2
-rw-r--r--testsuite/tests/typecheck/should_fail/T21444.hs8
-rw-r--r--testsuite/tests/typecheck/should_fail/T21444.stderr6
-rw-r--r--testsuite/tests/typecheck/should_fail/T7989.stderr15
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T1
-rw-r--r--testsuite/tests/typecheck/should_fail/tcfail114.stderr6
6 files changed, 20 insertions, 18 deletions
diff --git a/testsuite/tests/typecheck/should_fail/T12035.hs b/testsuite/tests/typecheck/should_fail/T12035.hs
index 87e20ff07c..cd12eee917 100644
--- a/testsuite/tests/typecheck/should_fail/T12035.hs
+++ b/testsuite/tests/typecheck/should_fail/T12035.hs
@@ -1,7 +1,7 @@
module T12035 where
import T12035a
type T = Bool
-y = f True
+--y = f True
-- This should error that 'type T = Int' doesn't match 'data T',
-- NOT that f expects argument of type T but got Bool.
diff --git a/testsuite/tests/typecheck/should_fail/T21444.hs b/testsuite/tests/typecheck/should_fail/T21444.hs
new file mode 100644
index 0000000000..28f2010dbd
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T21444.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE DuplicateRecordFields #-}
+
+module T21444 where
+
+data S = MkS { foo, bar, baz :: Int }
+data T = MkT { foo, bar, baz :: Int }
+
+blah x = x { foo = 1, bar = 2, baz = 3 }
diff --git a/testsuite/tests/typecheck/should_fail/T21444.stderr b/testsuite/tests/typecheck/should_fail/T21444.stderr
new file mode 100644
index 0000000000..cd4795c969
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T21444.stderr
@@ -0,0 +1,6 @@
+
+T21444.hs:8:10: error: [GHC-99339]
+ • Ambiguous record update with fields ‘foo’, ‘bar’ and ‘baz’
+ These fields appear in both datatypes ‘S’ and ‘T’
+ • In the expression: x {foo = 1, bar = 2, baz = 3}
+ In an equation for ‘blah’: blah x = x {foo = 1, bar = 2, baz = 3}
diff --git a/testsuite/tests/typecheck/should_fail/T7989.stderr b/testsuite/tests/typecheck/should_fail/T7989.stderr
index 7413b06648..f5271b2167 100644
--- a/testsuite/tests/typecheck/should_fail/T7989.stderr
+++ b/testsuite/tests/typecheck/should_fail/T7989.stderr
@@ -1,15 +1,4 @@
T7989.hs:6:7: error: [GHC-14392]
- • No constructor has all these fields: ‘a0’, ‘b0’
- • In the expression: x {a0 = 3, a1 = 2, b0 = 4, b1 = 5}
- In an equation for ‘f’: f x = x {a0 = 3, a1 = 2, b0 = 4, b1 = 5}
-
-T7989.hs:9:7: error: [GHC-14392]
- • No constructor has all these fields: ‘x’, ‘y’, ‘z’
- • In the expression: a {x = 0, y = 0, z = 0, v = 0}
- In an equation for ‘g’: g a = a {x = 0, y = 0, z = 0, v = 0}
-
-T7989.hs:11:7: error: [GHC-14392]
- • No constructor has all these fields: ‘x’, ‘a0’
- • In the expression: a {x = 0, a0 = 0}
- In an equation for ‘h’: h a = a {x = 0, a0 = 0}
+ Invalid record update.
+ No constructor in scope has all of the following fields: ‘a0’, ‘b0’
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 209f292737..2afc480451 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -675,3 +675,4 @@ test('T19627', normal, compile_fail, [''])
test('PatSynExistential', normal, compile_fail, [''])
test('PatSynArity', normal, compile_fail, [''])
test('PatSynUnboundVar', normal, compile_fail, [''])
+test('T21444', normal, compile_fail, [''])
diff --git a/testsuite/tests/typecheck/should_fail/tcfail114.stderr b/testsuite/tests/typecheck/should_fail/tcfail114.stderr
index 7516ebb712..b751b31cd0 100644
--- a/testsuite/tests/typecheck/should_fail/tcfail114.stderr
+++ b/testsuite/tests/typecheck/should_fail/tcfail114.stderr
@@ -1,5 +1,3 @@
-tcfail114.hs:11:20: error: [GHC-47535]
- • ‘foo’ is not a record selector
- • In the expression: undefined {foo = ()}
- In an equation for ‘test’: test = undefined {foo = ()}
+tcfail114.hs:11:20: error: [GHC-22385]
+ Not in scope: record field ‘foo’