From 22d7f146a4b11f89118fc4dd5939e09d2e4e652d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 4 Apr 2024 12:54:23 +0200 Subject: [PATCH] lib.types.attrTag: Fix declarationPositions after merge --- lib/tests/modules/types-attrTag.nix | 20 +++++++++++++++++--- lib/types.nix | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/tests/modules/types-attrTag.nix b/lib/tests/modules/types-attrTag.nix index ae676e347136..b2e5158bb44b 100644 --- a/lib/tests/modules/types-attrTag.nix +++ b/lib/tests/modules/types-attrTag.nix @@ -1,7 +1,8 @@ -{ lib, config, ... }: +{ lib, config, options, ... }: let inherit (lib) mkOption types; forceDeep = x: builtins.deepSeq x x; + mergedSubOption = (options.merged.type.getSubOptions options.merged.loc).extensible."merged."; in { options = { @@ -98,7 +99,7 @@ in merged.positive.yay = 100; merged.extensi-foo.extensible = "foo"; merged.extensi-bar.extensible = "bar"; - okChecks = + okChecks = builtins.addErrorContext "while evaluating the assertions" ( assert config.intStrings.hello == { right = "hello world"; }; assert config.intStrings.numberOne == { left = 1; }; assert config.merged.negative == { nay = false; }; @@ -115,7 +116,20 @@ in assert config.docs."submodules..qux".visible == true; # Not available (yet?) # assert config.docs."submodules..qux".declarationsWithPositions == [ ... ]; + assert options.submodules.declarations == [ __curPos.file ]; + assert lib.length options.submodules.declarationPositions == 1; + assert (lib.head options.submodules.declarationPositions).file == __curPos.file; + assert options.merged.declarations == [ __curPos.file __curPos.file ]; + assert lib.length options.merged.declarationPositions == 2; + assert (lib.elemAt options.merged.declarationPositions 0).file == __curPos.file; + assert (lib.elemAt options.merged.declarationPositions 1).file == __curPos.file; + assert (lib.elemAt options.merged.declarationPositions 0).line != (lib.elemAt options.merged.declarationPositions 1).line; + assert mergedSubOption.declarations == [ __curPos.file __curPos.file ]; + assert lib.length mergedSubOption.declarationPositions == 2; + assert (lib.elemAt mergedSubOption.declarationPositions 0).file == __curPos.file; + assert (lib.elemAt mergedSubOption.declarationPositions 1).file == __curPos.file; + assert (lib.elemAt mergedSubOption.declarationPositions 0).line != (lib.elemAt mergedSubOption.declarationPositions 1).line; assert lib.length config.docs."merged..extensible".declarations == 2; - true; + true); }; } diff --git a/lib/types.nix b/lib/types.nix index 694e800f5092..f7d878dfcbc5 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -707,7 +707,7 @@ rec { // { # mergeOptionDecls is not idempotent in these attrs: declarations = a.tags.${tagName}.declarations ++ bOpt.declarations; - declarationPositions = a.tags.${tagName}.declarations ++ bOpt.declarations; + declarationPositions = a.tags.${tagName}.declarationPositions ++ bOpt.declarationPositions; } ) (builtins.intersectAttrs a.tags b.tags);