summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorDavid Arnold <dgx.arnold@gmail.com>2021-07-23 14:10:31 -0500
committerDavid Arnold <dgx.arnold@gmail.com>2021-08-03 16:40:58 -0500
commitcf8e219b7e3c8933d6301175f2611990c5281ae9 (patch)
treeb0b4c0f097cd345dd452a1fbc8ed8b08f4f8dda4 /lib
parentd905ae22c60cafa7f94938c639d4518e1ddddcfa (diff)
downloadnixpkgs-cf8e219b7e3c8933d6301175f2611990c5281ae9.tar
nixpkgs-cf8e219b7e3c8933d6301175f2611990c5281ae9.tar.gz
nixpkgs-cf8e219b7e3c8933d6301175f2611990c5281ae9.tar.bz2
nixpkgs-cf8e219b7e3c8933d6301175f2611990c5281ae9.tar.lz
nixpkgs-cf8e219b7e3c8933d6301175f2611990c5281ae9.tar.xz
nixpkgs-cf8e219b7e3c8933d6301175f2611990c5281ae9.tar.zst
nixpkgs-cf8e219b7e3c8933d6301175f2611990c5281ae9.zip
lib: fix functionArgs for functors
`functionArgs` should give valid results on
functions that have been identified with `lib.isFunction`
instead of erroring out.
Diffstat (limited to 'lib')
-rw-r--r--lib/tests/misc.nix10
-rw-r--r--lib/trivial.nix5
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 0d249968402..4b2e5afc1d6 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -132,6 +132,16 @@ runTests {
     expected = [ 1 1 0 ];
   };
 
+  testFunctionArgsFunctor = {
+    expr = functionArgs { __functor = self: { a, b }: null; };
+    expected = { a = false; b = false; };
+  };
+
+  testFunctionArgsSetFunctionArgs = {
+    expr = functionArgs (setFunctionArgs (args: args.x) { x = false; });
+    expected = { x = false; };
+  };
+
 # STRINGS
 
   testConcatMapStrings = {
diff --git a/lib/trivial.nix b/lib/trivial.nix
index c8ef5599ccd..7956ba4bde6 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -334,7 +334,10 @@ rec {
      has the same return type and semantics as builtins.functionArgs.
      setFunctionArgs : (a → b) → Map String Bool.
   */
-  functionArgs = f: f.__functionArgs or (builtins.functionArgs f);
+  functionArgs = f:
+    if f ? __functor
+    then f.__functionArgs or (lib.functionArgs (f.__functor f))
+    else builtins.functionArgs f;
 
   /* Check whether something is a function or something
      annotated with function args.