Merge pull request #168374 from Ma27/special-attrs-in-with-recursion

lib/generators: withRecursion: don't break attr-sets with special attrs

authored by Silvan Mosberger and committed by GitHub 4b2827e6 c70995ba

+26 -1
+11 -1
lib/generators.nix
··· 251 251 }: 252 252 assert builtins.isInt depthLimit; 253 253 let 254 + specialAttrs = [ 255 + "__functor" 256 + "__functionArgs" 257 + "__toString" 258 + "__pretty" 259 + ]; 260 + stepIntoAttr = evalNext: name: 261 + if builtins.elem name specialAttrs 262 + then id 263 + else evalNext; 254 264 transform = depth: 255 265 if depthLimit != null && depth > depthLimit then 256 266 if throwOnDepthLimit ··· 261 271 let 262 272 evalNext = x: mapAny (depth + 1) (transform (depth + 1) x); 263 273 in 264 - if isAttrs v then mapAttrs (const evalNext) v 274 + if isAttrs v then mapAttrs (stepIntoAttr evalNext) v 265 275 else if isList v then map evalNext v 266 276 else transform (depth + 1) v; 267 277 in
+15
lib/tests/misc.nix
··· 674 674 expected = false; 675 675 }; 676 676 677 + testWithRecursionDealsWithFunctors = 678 + let 679 + functor = { 680 + __functor = self: { a, b, }: null; 681 + }; 682 + a = { 683 + value = "1234"; 684 + b = functor; 685 + c.d = functor; 686 + }; 687 + in { 688 + expr = generators.toPretty { } (generators.withRecursion { depthLimit = 1; throwOnDepthLimit = false; } a); 689 + expected = "{\n b = <function, args: {a, b}>;\n c = {\n d = \"<unevaluated>\";\n };\n value = \"<unevaluated>\";\n}"; 690 + }; 691 + 677 692 testToPrettyMultiline = { 678 693 expr = mapAttrs (const (generators.toPretty { })) rec { 679 694 list = [ 3 4 [ false ] ];