lib/modules: Report error for unsupported t // { check = ...; } (#454964)
This commit is contained in:
@@ -1126,6 +1126,29 @@ let
|
||||
__toString = _: showOption loc;
|
||||
};
|
||||
|
||||
# Check that a type with v2 merge has a coherent check attribute.
|
||||
# Throws an error if the type uses an ad-hoc `type // { check }` override.
|
||||
# Returns the last argument like `seq`, allowing usage: checkV2MergeCoherence loc type expr
|
||||
checkV2MergeCoherence =
|
||||
loc: type: result:
|
||||
if type.check.isV2MergeCoherent or false then
|
||||
result
|
||||
else
|
||||
throw ''
|
||||
The option `${showOption loc}' has a type `${type.description}' that uses
|
||||
an ad-hoc `type // { check = ...; }' override, which is incompatible with
|
||||
the v2 merge mechanism.
|
||||
|
||||
Please use `lib.types.addCheck` instead of `type // { check }' to add
|
||||
custom validation. For example:
|
||||
|
||||
lib.types.addCheck baseType (value: /* your check */)
|
||||
|
||||
instead of:
|
||||
|
||||
baseType // { check = value: /* your check */; }
|
||||
'';
|
||||
|
||||
# Merge definitions of a value of a given type.
|
||||
mergeDefinitions = loc: type: defs: rec {
|
||||
defsFinal' =
|
||||
@@ -1201,10 +1224,13 @@ let
|
||||
(
|
||||
if type.merge ? v2 then
|
||||
let
|
||||
r = type.merge.v2 {
|
||||
inherit loc;
|
||||
defs = defsFinal;
|
||||
};
|
||||
# Check for v2 merge coherence
|
||||
r = checkV2MergeCoherence loc type (
|
||||
type.merge.v2 {
|
||||
inherit loc;
|
||||
defs = defsFinal;
|
||||
}
|
||||
);
|
||||
in
|
||||
r
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user