diff options
author | Silvan Mosberger <contact@infinisil.com> | 2020-03-16 21:10:05 +0100 |
---|---|---|
committer | Silvan Mosberger <contact@infinisil.com> | 2020-03-18 04:38:53 +0100 |
commit | e931de58a2f724c3632b7c8a656fb47489ecc963 (patch) | |
tree | 1b56b24a3d4b0655e2ef3de6964e8e6203ea346f /lib | |
parent | 15c873b486347e7861c64fb0b5a7852be9fc82e4 (diff) |
lib/modules: Fix type checks not being done before merging
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/modules.nix | 7 | ||||
-rwxr-xr-x | lib/tests/modules.sh | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/modules.nix b/lib/modules.nix index 22df89f360ac..518f4047cc60 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -416,10 +416,9 @@ rec { # Type-check the remaining definitions, and merge them. Or throw if no definitions. mergedValue = if isDefined then - foldl' (res: def: - if type.check def.value then res - else throw "The option value `${showOption loc}' in `${def.file}' is not of type `${type.description}'." - ) (type.merge loc defsFinal) defsFinal + if all (def: type.check def.value) defsFinal then type.merge loc defsFinal + else let firstInvalid = findFirst (def: ! type.check def.value) null defsFinal; + in throw "The option value `${showOption loc}' in `${firstInvalid.file}' is not of type `${type.description}'." else # (nixos-option detects this specific error message and gives it special # handling. If changed here, please change it there too.) diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 0e2fd0bf65d2..7713207dadda 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -198,6 +198,10 @@ checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-c checkConfigError 'The option path .* is an attribute set of options, but it is defined to not be an attribute set in' \ config.value ./declare-option-set.nix ./define-value-int-zero.nix +# Even with multiple assignments, a type error should be thrown if any of them aren't valid +checkConfigError 'The option value .* in .* is not of type .*' \ + config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix + cat <<EOF ====== module tests ====== $pass Pass |