Commit 1c9ffbe6 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com
Browse files

Fix Trac #2141: invalid record update

See Note [Record field lookup] in TcEnv.  The fix here
is quite straightforward.
parent c245355e
...@@ -134,10 +134,22 @@ tcLookupGlobal name ...@@ -134,10 +134,22 @@ tcLookupGlobal name
tcLookupField :: Name -> TcM Id -- Returns the selector Id tcLookupField :: Name -> TcM Id -- Returns the selector Id
tcLookupField name = do tcLookupField name = do
thing <- tcLookupGlobal name thing <- tcLookup name -- Note [Record field lookup]
case thing of case thing of
AnId id -> return id AGlobal (AnId id) -> return id
other -> wrongThingErr "field name" (AGlobal thing) name 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 -> TcM DataCon
tcLookupDataCon name = do tcLookupDataCon name = do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment