diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2013-06-25 14:16:29 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2013-06-25 14:16:48 +0100 |
commit | a7798e95112409b6ec958e509dbdc46bc53cf5e4 (patch) | |
tree | 09d1d0aef150e2805f194ca168202a13605d4b3e | |
parent | d67b99347f5af146b699b1df174687a4de08fa1a (diff) | |
download | haskell-a7798e95112409b6ec958e509dbdc46bc53cf5e4.tar.gz |
Comments for Trac #7989
-rw-r--r-- | compiler/typecheck/TcExpr.lhs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/compiler/typecheck/TcExpr.lhs b/compiler/typecheck/TcExpr.lhs index 31c1e06ef7..b353a52bdf 100644 --- a/compiler/typecheck/TcExpr.lhs +++ b/compiler/typecheck/TcExpr.lhs @@ -1519,9 +1519,10 @@ badFieldsUpd badFieldsUpd rbinds data_cons = hang (ptext (sLit "No constructor has all these fields:")) 2 (pprQuotedList conflictingFields) + -- See Note [Finding the conflicting fields] where -- A (preferably small) set of fields such that no constructor contains - -- all of them. + -- all of them. See Note [Finding the conflicting fields] conflictingFields = case nonMembers of -- nonMember belongs to a different type. (nonMember, _) : _ -> [aMember, nonMember] @@ -1560,7 +1561,32 @@ badFieldsUpd rbinds data_cons map (\ item@(_, membershipRow) -> (countTrue membershipRow, item)) countTrue = length . filter id +\end{code} + +Note [Finding the conflicting fields] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Suppose we have + data A = A {a0, a1 :: Int} + | B {b0, b1 :: Int} +and we see a record update + x { a0 = 3, a1 = 2, b0 = 4, b1 = 5 } +Then we'd like to find the smallest subset of fields that no +constructor has all of. Here, say, {a0,b0}, or {a0,b1}, etc. +We don't really want to report that no constructor has all of +{a0,a1,b0,b1}, because when there are hundreds of fields it's +hard to see what was really wrong. + +We may need more than two fields, though; eg + data T = A { x,y :: Int, v::Int } + | B { y,z :: Int, v::Int } + | C { z,x :: Int, v::Int } +with update + r { x=e1, y=e2, z=e3 }, we + +Finding the smallest subset is hard, so the code here makes +a decent stab, no more. See Trac #7989. +\begin{code} naughtyRecordSel :: TcId -> SDoc naughtyRecordSel sel_id = ptext (sLit "Cannot use record selector") <+> quotes (ppr sel_id) <+> |