Fix Trac #3176: intercept naughty record selectors
authorsimonpj@microsoft.com <unknown>
Thu, 23 Apr 2009 09:42:37 +0000 (09:42 +0000)
committersimonpj@microsoft.com <unknown>
Thu, 23 Apr 2009 09:42:37 +0000 (09:42 +0000)
When making record selectors into ordinary functions (rather than
magial implicit Ids) I forgot that they could therefore show up in
the *local* TcEnv, not the global one.  This fixes that problem,
and thereby Trac #3176.

compiler/typecheck/TcExpr.lhs

index 51d6f4b..b255fdb 100644 (file)
@@ -1069,6 +1069,9 @@ lookupFun orig id_name
                -- nor does it need the 'lifting' treatment
 
            ATcId { tct_id = id, tct_type = ty, tct_co = mb_co, tct_level = lvl }
                -- nor does it need the 'lifting' treatment
 
            ATcId { tct_id = id, tct_type = ty, tct_co = mb_co, tct_level = lvl }
+               | isNaughtyRecordSelector id -> failWithTc (naughtyRecordSel id)
+                                         -- Note [Local record selectors]
+               | otherwise
                -> do { thLocalId orig id ty lvl
                      ; case mb_co of
                          Unrefineable    -> return (HsVar id, ty)
                -> do { thLocalId orig id ty lvl
                      ; case mb_co of
                          Unrefineable    -> return (HsVar id, ty)
@@ -1147,6 +1150,12 @@ thBrackId orig id ps_var lie_var
 #endif /* GHCI */
 \end{code}
 
 #endif /* GHCI */
 \end{code}
 
+Local record selectors
+~~~~~~~~~~~~~~~~~~~~~~
+Record selectors for TyCons in this module are ordinary local bindings,
+which show up as ATcIds rather than AGlobals.  So we need to check for
+naughtiness in both branches.  c.f. TcTyClsBindings.mkAuxBinds.
+
 
 %************************************************************************
 %*                                                                     *
 
 %************************************************************************
 %*                                                                     *