mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-05 21:03:40 +00:00
lib.types.defaultTypeMerge: Fix for functors with no wrapped attr (#476219)
This commit is contained in:
@@ -734,6 +734,8 @@ checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survive
|
||||
# Test that specifying both functor.wrapped and functor.payload isn't allowed
|
||||
checkConfigError 'Type foo defines both `functor.payload` and `functor.wrapped` at the same time, which is not supported.' config.result ./default-type-merge-both.nix
|
||||
|
||||
# Test that not including functor.wrapped is allowed
|
||||
checkConfigOutput 'ok' config.result ./default-type-merge-payload.nix
|
||||
|
||||
# Anonymous submodules don't get nixed by import resolution/deduplication
|
||||
# because of an `extendModules` bug, issue 168767.
|
||||
|
||||
32
lib/tests/modules/default-type-merge-payload.nix
Normal file
32
lib/tests/modules/default-type-merge-payload.nix
Normal file
@@ -0,0 +1,32 @@
|
||||
{ lib, options, ... }:
|
||||
let
|
||||
fooOf =
|
||||
elemType:
|
||||
lib.mkOptionType {
|
||||
name = "foo";
|
||||
functor = {
|
||||
name = "foo";
|
||||
type = payload: fooOf payload.elemType;
|
||||
binOp = a: _b: a;
|
||||
payload.elemType = elemType;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
{
|
||||
options.foo = lib.mkOption {
|
||||
type = fooOf lib.types.int;
|
||||
};
|
||||
}
|
||||
{
|
||||
options.foo = lib.mkOption {
|
||||
type = fooOf lib.types.int;
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
options.result = lib.mkOption {
|
||||
default = builtins.seq options.foo "ok";
|
||||
};
|
||||
}
|
||||
@@ -158,8 +158,11 @@ rec {
|
||||
assert (f'.payload != null) == (f.payload != null);
|
||||
f.payload != null;
|
||||
hasWrapped =
|
||||
assert (f'.wrapped != null) == (f.wrapped != null);
|
||||
f.wrapped != null;
|
||||
let
|
||||
hasWrappedNonNull = set: set ? "wrapped" && set.wrapped != null;
|
||||
in
|
||||
assert (hasWrappedNonNull f') == (hasWrappedNonNull f);
|
||||
hasWrappedNonNull f;
|
||||
|
||||
typeFromPayload = if mergedPayload == null then null else f.type mergedPayload;
|
||||
typeFromWrapped = if mergedWrapped == null then null else f.type mergedWrapped;
|
||||
|
||||
Reference in New Issue
Block a user