From dde85e2794b9263b619faa21482e495a4692d00b Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Wed, 18 Nov 2026 07:40:13 -0600 Subject: [PATCH] Fix implicit_requirement change from sourced modulefile The module modulefile command tests the implicit_requirement option twice: before running the sub-command to push an entry on the inhibit_req_record state, then after to pop it. When the sub-command is "config implicit_requirement ", the option value changes between these two tests. When the option is disabled this way from an initialization rc file or a sourced modulefile, the state is popped without having been pushed, which raises an error as this state is not defined. When the option is enabled, the pushed entry is never removed. Evaluate the condition once before running the sub-command and reuse its result afterward, so push and pop are always paired. Fixes #740 Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- NEWS.rst | 4 ++++ tcl/mfcmd.tcl | 6 ++++-- .../modules.50-cmds/430-implicit-req.exp | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index 1024483e5..7070ad5f6 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -73,6 +73,10 @@ Modules 5.8.0 (not yet released) commands to support modulerc files written for Lmod. They are aliases of :mfcmd:`module-forbid` and :mfcmd:`module-hide` with ``--regexp`` option set. +* Fix error raised when the :mconfig:`implicit_requirement` configuration + option is changed with the :subcmd:`config` sub-command from an + initialization rc file or a sourced modulefile. (fix issue #740 with + contribution from Achim Gsell) .. _5.7 release notes: diff --git a/tcl/mfcmd.tcl b/tcl/mfcmd.tcl index 9f54b19a1..a408ae11c 100644 --- a/tcl/mfcmd.tcl +++ b/tcl/mfcmd.tcl @@ -2705,7 +2705,9 @@ proc module {command args} { knerrorModule 0 "Command '$command' not supported" } # no requirement should be recorded this module load/unload/switch cmd - if {$not_req || ![getConf implicit_requirement]} { + # test made once as config sub-command may change implicit_requirement + set inhibit_req [expr {$not_req || ![getConf implicit_requirement]}] + if {$inhibit_req} { lappendState inhibit_req_record [currentState evalid] } @@ -2718,7 +2720,7 @@ proc module {command args} { lpopState commandname lpopState always_read_full_file - if {$not_req || ![getConf implicit_requirement]} { + if {$inhibit_req} { lpopState inhibit_req_record } diff --git a/testsuite/modules.50-cmds/430-implicit-req.exp b/testsuite/modules.50-cmds/430-implicit-req.exp index e42d8b580..146b0f573 100644 --- a/testsuite/modules.50-cmds/430-implicit-req.exp +++ b/testsuite/modules.50-cmds/430-implicit-req.exp @@ -497,6 +497,27 @@ unsetenv_var __MODULES_LMTAG unsetenv_loaded_module +# +# change implicit_requirement with config sub-command from sourced file +# + +set modfile [file join [pwd] impreqconfig.mod] +set fid [open $modfile w] +puts $fid {#%Module +module config implicit_requirement $env(TESTSUITE_IMPLICIT_REQ)} +close $fid + +foreach {cur new} {1 0 0 1 1 1 0 0} { + setenv_var MODULES_IMPLICIT_REQUIREMENT $cur + setenv_var TESTSUITE_IMPLICIT_REQ $new + set ans [list [list set MODULES_IMPLICIT_REQUIREMENT $new]] + testouterr_cmd sh "source $modfile" $ans {} +} + +unsetenv_var TESTSUITE_IMPLICIT_REQ +file delete $modfile + + # # Cleanup #