Skip to content

Commit

Permalink
lib.types.defaultTypeMerge: add 'loc' to default type merge
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjobeki committed Nov 24, 2024
1 parent a6c4d71 commit ac86702
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let
concatLists
concatMap
concatStringsSep
defaultTypeMerge
elem
filter
foldl'
Expand Down Expand Up @@ -749,7 +750,7 @@ let
foldl' (res: opt:
let t = res.type;
t' = opt.options.type;
mergedType = t.typeMerge t'.functor;
mergedType = defaultTypeMerge loc t.functor t'.functor;
typesMergeable = mergedType != null;
typeSet = if (bothHave "type") && typesMergeable
then { type = mergedType; }
Expand Down
6 changes: 4 additions & 2 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ rec {

# Default type merging function
# takes two type functors and return the merged type
defaultTypeMerge = f: f':
defaultTypeMerge = loc: f: f':
let mergedWrapped = f.wrapped.typeMerge f'.wrapped.functor;
mergedPayload = f.binOp f.payload f'.payload;

Expand All @@ -103,6 +103,8 @@ rec {
Use either `functor.payload` or `functor.wrapped` but not both.
If your code worked before remove `functor.payload` from the type definition.
Location: ${showOption loc}
''
else
# Has payload
Expand Down Expand Up @@ -182,7 +184,7 @@ rec {
, # Function that merge type declarations.
# internal, takes a functor as argument and returns the merged type.
# returning null means the type is not mergeable
typeMerge ? defaultTypeMerge functor
typeMerge ? defaultTypeMerge ["unknown location"] functor
, # The type functor.
# internal, representation of the type as an attribute set.
# name: name of the type
Expand Down

0 comments on commit ac86702

Please sign in to comment.