Description
I am using haskell-names
to implement a simple renaming pass (including the module name in the symbol name), and I stumbled over a small lack of information on punned names.
Consider
{-# LANGUAGE RecordWildCards #-}
module RecordSelector where
data Record a = Record { field :: a }
unRecord r = field
where Record { .. } = r
Here, the annotation I get for the use field
in unRecord
is
Var
(Scoped None
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 4 14 4 19,
srcInfoPoints = []}))
(UnQual
(Scoped (LocalValue (SrcLoc "RecordSelector.hs" 6 14))
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 4 14 4 19,
srcInfoPoints = []}))
(Ident
(Scoped (LocalValue (SrcLoc "RecordSelector.hs" 6 14))
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 4 14 4 19,
srcInfoPoints = []}))
"field")))
so it says it is a locally defined value bound at position 6:14, but the requirement that the name is equal to the name of the record field is lost. So if I rename the record field, the program fails to compile.
Even if I use non-local information and look at what’s at 6:14, I find
PFieldWildcard
(Scoped (RecPatWildcard [])
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 6 14 6 16,
srcInfoPoints = []}))
which is not very helpful.
Relatedly, if I change ..
to field = field
, I find
PFieldPat
(Scoped None
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 6 14 6 25,
srcInfoPoints = [SrcSpan "RecordSelector.hs" 6 19 6 20]}))
(UnQual
(Scoped (LocalValue (SrcLoc "RecordSelector.hs" 6 20))
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 6 14 6 19,
srcInfoPoints = []}))
(Ident
(Scoped (LocalValue (SrcLoc "RecordSelector.hs" 6 20))
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 6 14 6 19,
srcInfoPoints = []}))
"field"))
(PVar
(Scoped None
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 6 20 6 25,
srcInfoPoints = []}))
(Ident
(Scoped ValueBinder
(SrcSpanInfo{srcInfoSpan = SrcSpan "RecordSelector.hs" 6 20 6 25,
srcInfoPoints = []}))
"field"))]
which says that the left field
(the constructor field, at 6:14) is a local value bound at the position of the right name field
(the variable, at 6:20), which is certainly wrong.