Skip to content

Commit 95179df

Browse files
committed
Fix isString to refrain from coercing values
Derivations can be automatically coerced to strings. They are however not strings and `isString` should return `False` on them.
1 parent f7c99be commit 95179df

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Nix/Builtins.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,6 @@ isList
10401040
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
10411041
isList = hasKind @[NValue t f m]
10421042

1043-
isString
1044-
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
1045-
isString = hasKind @NixString
1046-
10471043
isInt
10481044
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
10491045
isInt = hasKind @Int
@@ -1060,6 +1056,12 @@ isNull
10601056
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
10611057
isNull = hasKind @()
10621058

1059+
-- isString cannot use `hasKind` because it coerces derivations to strings.
1060+
isString :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
1061+
isString v = demand v $ \case
1062+
NVStr{} -> toValue True
1063+
_ -> toValue False
1064+
10631065
isFunction :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
10641066
isFunction func = demand func $ \case
10651067
NVClosure{} -> toValue True

0 commit comments

Comments
 (0)