X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcEnv.lhs;h=1f9d3050eff2fd7094b829ee8ace3e4949b43511;hb=a27c5f77da8b3b3f00f9902b69a504460f234e8c;hp=ad45c7ca4cafd399d43d71c7a121f9102dd65fb0;hpb=288213d7c2c65fa68ca466c1a1a3378e24fa1151;p=ghc-hetmet.git diff --git a/compiler/typecheck/TcEnv.lhs b/compiler/typecheck/TcEnv.lhs index ad45c7c..1f9d305 100644 --- a/compiler/typecheck/TcEnv.lhs +++ b/compiler/typecheck/TcEnv.lhs @@ -81,6 +81,7 @@ import HscTypes import SrcLoc import Outputable import Maybes +import FastString \end{code} @@ -133,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