Last active
February 8, 2022 13:42
-
-
Save GrafBlutwurst/1c22253b66dd8cab7ecd158e19bafcf0 to your computer and use it in GitHub Desktop.
Example of how lists type merge breaks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
pkgs = import <nixpkgs> { }; | |
in | |
with pkgs.lib; with pkgs.lib.types; let | |
leftType = submodule { | |
options.foo = mkOption { | |
type = int; | |
description = "left.foo"; | |
}; | |
}; | |
rightType = submodule { | |
options.bar = mkOption { | |
type = string; | |
description = "right.bar"; | |
}; | |
}; | |
loc = [ "dummy" ]; | |
leftValue = { foo = 1; }; | |
rightValue = { bar = 1; }; | |
rightValueWrong = { bar = true; }; | |
defs = { | |
testCase1 = [ | |
{ file = "f1"; value = [ leftValue ]; } | |
]; | |
testCase2 = [ | |
{ file = "f1"; value = [ leftValue leftValue ]; } | |
]; | |
testCase3 = [ | |
{ file = "f1"; value = [ leftValue leftValue ]; } | |
{ file = "f2"; value = [ leftValue leftValue ]; } | |
]; | |
testCase4 = [ | |
{ file = "f1"; value = [ rightValue ]; } | |
]; | |
testCase5 = [ | |
{ file = "f1"; value = [ leftValue ]; } | |
{ file = "f2"; value = [ rightValue ]; } | |
]; | |
testCase6 = [ | |
{ file = "f1"; value = [ rightValueWrong ]; } | |
]; | |
}; | |
#This doesn't work because list merge breaks for inner eithers | |
callMerge = defs: | |
let | |
typeDef = listOf (either leftType rightType); | |
in | |
typeDef.merge loc defs; | |
#This doesnt work because it no longer propertly checks the correctness of the records in the list | |
#Same happens if uniq is on the either | |
callMergeUniq = defs: | |
let | |
typeDef = uniq (listOf (either leftType rightType)); | |
#typeDef = listOf (uniq (either leftType rightType)); | |
in | |
typeDef.merge loc defs; | |
in | |
{ | |
nonUniq = { | |
testCase1 = callMerge defs.testCase1; | |
testCase2 = callMerge defs.testCase2; | |
testCase3 = callMerge defs.testCase3; | |
#Seems like something with lists merge is funny ending up always trying to apply the first arugment of the inner either. | |
#testCase4Breaks = callMerge defs.testCase4; | |
#testCase5Breaks = callMerge defs.testCase5; | |
}; | |
withUniq = { | |
testCase1 = callMergeUniq defs.testCase1; | |
testCase2 = callMergeUniq defs.testCase2; | |
#Makes sense that it breaks since we made it uniq | |
#testCase3Breaks = callMergeUniq defs.testCase3; | |
testCase4 = callMergeUniq defs.testCase4; | |
#Makes sense that it breaks since we made it uniq | |
#testCase5Breaks = callMergeUniq defs.testCase5; | |
testCase6 = callMergeUniq defs.testCase6; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment