summaryrefslogtreecommitdiff
path: root/compiler/Language/Haskell/Syntax/Expr.hs
diff options
context:
space:
mode:
authorShayne Fletcher <shayne@shaynefletcher.org>2021-04-24 16:59:26 -0400
committerShayne Fletcher <shayne@shaynefletcher.org>2021-04-26 18:52:13 -0400
commit76f82c0eb0212a1d6d2712996b4f19984aec80be (patch)
treed86f70f6b432ddbeadc6d427d8c366718468be33 /compiler/Language/Haskell/Syntax/Expr.hs
parent7bc7eea3897dcb8a87fdb0921f451b9bc77309f6 (diff)
downloadhaskell-wip/T19720.tar.gz
Change representation of field selector occurenceswip/T19720
Diffstat (limited to 'compiler/Language/Haskell/Syntax/Expr.hs')
-rw-r--r--compiler/Language/Haskell/Syntax/Expr.hs24
1 files changed, 20 insertions, 4 deletions
diff --git a/compiler/Language/Haskell/Syntax/Expr.hs b/compiler/Language/Haskell/Syntax/Expr.hs
index e7756cc804..17a0929976 100644
--- a/compiler/Language/Haskell/Syntax/Expr.hs
+++ b/compiler/Language/Haskell/Syntax/Expr.hs
@@ -265,6 +265,24 @@ is Less Cool because
typecheck do-notation with (>>=) :: m1 a -> (a -> m2 b) -> m2 b.)
-}
+{-
+Note [Non-overloaded record field selectors]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Consider
+ data T = MkT { x,y :: Int }
+ f r x = x + y r
+
+This parses with HsVar for x, y, r on the RHS of f. Then, if
+-XOverloadedRecordFields is /off/, the renamer recognises that y in
+the RHS of f is really a record selector, and changes it to a
+HsRecFld. In contrast x is locally bound, shadowing the record
+selector, and stay as an HsVar.
+
+The renamer adds the Name of the record selector into the XRecFld
+extension field, The typechecker keeps HsRecFld as HsRecFld, and
+transforms the record-selector Name to an Id.
+-}
+
-- | A Haskell expression.
data HsExpr p
= HsVar (XVar p)
@@ -287,10 +305,8 @@ data HsExpr p
-- HsVar for pretty printing
| HsRecFld (XRecFld p)
- (AmbiguousFieldOcc p) -- ^ Variable pointing to record selector
- -- The parser produces HsVars
- -- The renamer renames record-field selectors to HsRecFld
- -- The typechecker preserves HsRecFld
+ (FieldOcc p) -- ^ Variable pointing to record selector
+ -- See Note [Non-overloaded record field selectors]
| HsOverLabel (XOverLabel p) FastString
-- ^ Overloaded label (Note [Overloaded labels] in GHC.OverloadedLabels)