Skip to content

Commit

Permalink
Fix isString to refrain from coercing values
Browse files Browse the repository at this point in the history
Derivations can be automatically coerced to strings. They are however
not strings and `isString` should return `False` on them.
  • Loading branch information
layus committed Nov 18, 2020
1 parent 48ed345 commit d32a6fb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,10 +1040,6 @@ isList
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isList = hasKind @[NValue t f m]

isString
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isString = hasKind @NixString

isInt
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isInt = hasKind @Int
Expand All @@ -1060,6 +1056,12 @@ isNull
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isNull = hasKind @()

-- isString cannot use `hasKind` because it coerces derivations to strings.
isString :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
isString v = demand v $ \case
NVStr{} -> toValue True
_ -> toValue False

isFunction :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
isFunction func = demand func $ \case
NVClosure{} -> toValue True
Expand Down

0 comments on commit d32a6fb

Please sign in to comment.