Merge pull request #131267 from blaggacao/fix-functionArgs

lib: fix functionArgs for functors

authored by

Silvan Mosberger and committed by
GitHub
f0fda3bf 1ab9b0e3

+14 -1
+10
lib/tests/misc.nix
··· 132 132 expected = [ 1 1 0 ]; 133 133 }; 134 134 135 + testFunctionArgsFunctor = { 136 + expr = functionArgs { __functor = self: { a, b }: null; }; 137 + expected = { a = false; b = false; }; 138 + }; 139 + 140 + testFunctionArgsSetFunctionArgs = { 141 + expr = functionArgs (setFunctionArgs (args: args.x) { x = false; }); 142 + expected = { x = false; }; 143 + }; 144 + 135 145 # STRINGS 136 146 137 147 testConcatMapStrings = {
+4 -1
lib/trivial.nix
··· 334 334 has the same return type and semantics as builtins.functionArgs. 335 335 setFunctionArgs : (a → b) → Map String Bool. 336 336 */ 337 - functionArgs = f: f.__functionArgs or (builtins.functionArgs f); 337 + functionArgs = f: 338 + if f ? __functor 339 + then f.__functionArgs or (lib.functionArgs (f.__functor f)) 340 + else builtins.functionArgs f; 338 341 339 342 /* Check whether something is a function or something 340 343 annotated with function args.