From 976def943b2fccfaf34adc31a66e58bfa0760678 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Sun, 22 Nov 2009 21:28:43 +0000 Subject: nix lib: add nixType returning type of value as string which is used in eqStrict now to return false when a b have different types. Passing string and {} to eqStrict caused coercion failures when running tests previously svn path=/nixpkgs/trunk/; revision=18539 --- pkgs/lib/misc.nix | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'pkgs/lib/misc.nix') diff --git a/pkgs/lib/misc.nix b/pkgs/lib/misc.nix index c1fee190268..e3215d9ec56 100644 --- a/pkgs/lib/misc.nix +++ b/pkgs/lib/misc.nix @@ -1,5 +1,5 @@ let lib = import ./default.nix; - inherit (builtins) isFunction hasAttr getAttr head tail isList isAttrs attrNames; + inherit (builtins) isFunction hasAttr getAttr head tail isList isAttrs isInt attrNames; in @@ -348,6 +348,18 @@ rec { ["flags" "cfg" "mergeAttrBy" ]; + nixType = x: + if isAttrs x then + if x ? outPath then "derivation" + else "aattrs" + else if isFunction x then "function" + else if isList x then "list" + else if x == true then "bool" + else if x == false then "bool" + else if x == null then "null" + else if isInt x then "int" + else "string"; + # deep, strict equality testing. This should be implemented as primop eqStrict = a : b : let eqListStrict = a : b : @@ -355,9 +367,10 @@ rec { else if a == [] then true else eqStrict (head a) (head b) && eqListStrict (tail a) (tail b); in - if isList a && isList b then eqListStrict a b - else if isAttrs a && isAttrs b then - (eqListStrict (attrNames a) (attrNames b)) - && (eqListStrict (lib.attrValues a) (lib.attrValues b)) - else a == b; # FIXME ! + if nixType a != nixType b then false + else if isList a then eqListStrict a b + else if isAttrs a then + (eqListStrict (attrNames a) (attrNames b)) + && (eqListStrict (lib.attrValues a) (lib.attrValues b)) + else a == b; # FIXME ! } -- cgit 1.4.1