From 1c9ffbe64003cef8a686ff1e29aae160e314775e Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Wed, 2 Apr 2008 13:20:57 +0000 Subject: [PATCH] Fix Trac #2141: invalid record update See Note [Record field lookup] in TcEnv. The fix here is quite straightforward. --- compiler/typecheck/TcEnv.lhs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/compiler/typecheck/TcEnv.lhs b/compiler/typecheck/TcEnv.lhs index aa27a43..1f9d305 100644 --- a/compiler/typecheck/TcEnv.lhs +++ b/compiler/typecheck/TcEnv.lhs @@ -134,10 +134,22 @@ tcLookupGlobal name tcLookupField :: Name -> TcM Id -- Returns the selector Id tcLookupField name = do - thing <- tcLookupGlobal name + thing <- tcLookup name -- Note [Record field lookup] case thing of - AnId id -> return id - other -> wrongThingErr "field name" (AGlobal thing) name + AGlobal (AnId id) -> return id + thing -> wrongThingErr "field name" thing name + +{- Note [Record field lookup] + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +You might think we should have tcLookupGlobal here, since record fields +are always top level. But consider + f = e { f = True } +Then the renamer (which does not keep track of what is a record selector +and what is not) will rename the definition thus + f_7 = e { f_7 = True } +Now the type checker will find f_7 in the *local* type environment, not +the global one. It's wrong, of course, but we want to report a tidy +error, not in TcEnv.notFound. -} tcLookupDataCon :: Name -> TcM DataCon tcLookupDataCon name = do -- 1.7.10.4