git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #124353 from hercules-ci/small-enum-description

lib.types.enum: Improve description for lengths 0 and 1

commit6d29becbd3f181b4efbf05bab466e272a7beabc1 authorRobert Hensing <roberth@users.noreply.github.com> dateSun 18 Jul 2021, 19:08 (5 years ago) parent03a17d72856323
1 file changed+11−1
lib/types.nix+11−1
lib/types.nix+11−1
@@ -581,7 +581,17 @@ rec {
581581 in
582582 mkOptionType rec {
583583 name = "enum";
584− description = "one of ${concatMapStringsSep ", " show values}";
584+ description =
585+ # Length 0 or 1 enums may occur in a design pattern with type merging
586+ # where an "interface" module declares an empty enum and other modules
587+ # provide implementations, each extending the enum with their own
588+ # identifier.
589+ if values == [] then
590+ "impossible (empty enum)"
591+ else if builtins.length values == 1 then
592+ "value ${show (builtins.head values)} (singular enum)"
593+ else
594+ "one of ${concatMapStringsSep ", " show values}";
585595 check = flip elem values;
586596 merge = mergeEqualOption;
587597 functor = (defaultFunctor name) // { payload = values; binOp = a: b: unique (a ++ b); };