Skip to content

Commit

Permalink
lib/modules: Fix type checks not being done before merging
Browse files Browse the repository at this point in the history
Co-Authored-By: Robert Hensing <[email protected]>
  • Loading branch information
infinisil and roberth committed Mar 18, 2020
1 parent 15c873b commit e931de5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
4 changes: 4 additions & 0 deletions lib/tests/modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e931de5

Please sign in to comment.