Skip to content

Commit 758f566

Browse files
committed
Add hasUpperBound and hasLowerBound
This is useful for performing PVP bounds checking, especially for tooling that wants to automate such dependency bounds. A demonstration of this being used in practice is the --pvp-bounds flag for stack: commercialhaskell/stack@c774f99
1 parent 74e8ebf commit 758f566

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Cabal/Distribution/Version.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ module Distribution.Version (
4444
simplifyVersionRange,
4545
foldVersionRange,
4646
foldVersionRange',
47+
hasUpperBound,
48+
hasLowerBound,
4749

4850
-- ** Modification
4951
removeUpperBound,
@@ -805,3 +807,29 @@ instance Text VersionRange where
805807
(">", LaterVersion),
806808
(">=", orLaterVersion),
807809
("==", ThisVersion) ]
810+
811+
-- | Does the version range have an upper bound?
812+
--
813+
-- @since 1.24.0.0
814+
hasUpperBound :: VersionRange -> Bool
815+
hasUpperBound AnyVersion = False
816+
hasUpperBound (ThisVersion _) = True
817+
hasUpperBound (LaterVersion _) = False
818+
hasUpperBound (EarlierVersion _) = True
819+
hasUpperBound (WildcardVersion _) = True
820+
hasUpperBound (UnionVersionRanges x y) = hasUpperBound x && hasUpperBound y
821+
hasUpperBound (IntersectVersionRanges x y) = hasUpperBound x && hasUpperBound y
822+
hasUpperBound (VersionRangeParens x) = hasUpperBound x
823+
824+
-- | Does the version range have a lower bound?
825+
--
826+
-- @since 1.24.0.0
827+
hasLowerBound :: VersionRange -> Bool
828+
hasLowerBound AnyVersion = False
829+
hasLowerBound (ThisVersion _) = True
830+
hasLowerBound (LaterVersion _) = True
831+
hasLowerBound (EarlierVersion _) = False
832+
hasLowerBound (WildcardVersion _) = True
833+
hasLowerBound (UnionVersionRanges x y) = hasLowerBound x && hasLowerBound y
834+
hasLowerBound (IntersectVersionRanges x y) = hasLowerBound x && hasLowerBound y
835+
hasLowerBound (VersionRangeParens x) = hasLowerBound x

0 commit comments

Comments
 (0)