Skip to content

Commit 24094c4

Browse files
committed
Expr.Types.Annotated: nSelectLoc: refactor, leave a note on Monoid
1 parent 7211f79 commit 24094c4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Nix/Expr/Types/Annotated.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,15 @@ nBinary (Ann s1 b) e1@(AnnE s2 _) e2@(AnnE s3 _) =
157157

158158
nSelectLoc
159159
:: NExprLoc -> Ann SrcSpan (NAttrPath NExprLoc) -> Maybe NExprLoc -> NExprLoc
160-
nSelectLoc e1@(AnnE s1 _) (Ann s2 ats) d = case d of
161-
Nothing -> AnnE (s1 <> s2) $ NSelect e1 ats Nothing
162-
Just e2@(AnnE s3 _) -> AnnE (s1 <> s2 <> s3) $ NSelect e1 ats $ pure e2
160+
nSelectLoc e1@(AnnE s1 _) (Ann s2 ats) =
161+
-- 2021-05-16: NOTE: This could been rewritten into function application of @(s3, pure e2)@
162+
-- if @SrcSpan@ was Monoid, which requires @SorcePos@ to be a Monoid, and upstream code prevents it.
163+
-- Question upstream: https://github.com/mrkkrp/megaparsec/issues/450
164+
maybe
165+
( AnnE s1s2 $ NSelect e1 ats Nothing)
166+
(\ e2@(AnnE s3 _) -> AnnE (s1s2 <> s3) $ NSelect e1 ats $ pure e2)
167+
where
168+
s1s2 = s1 <> s2
163169

164170
nHasAttr :: NExprLoc -> Ann SrcSpan (NAttrPath NExprLoc) -> NExprLoc
165171
nHasAttr e1@(AnnE s1 _) (Ann s2 ats) = AnnE (s1 <> s2) $ NHasAttr e1 ats

0 commit comments

Comments
 (0)