Warn if a variable is UNSET without having been used (if -du is in effect)

This commit is contained in:
Dianne Skoll
2025-05-24 23:13:39 -04:00
parent 5035deaff1
commit 51a65841cd
3 changed files with 7 additions and 0 deletions

View File

@@ -581,6 +581,9 @@ int DeleteVar(char const *str)
v = FindVar(str, 0);
if (!v) return E_NOSUCH_VAR;
if ((DebugFlag & DB_UNUSED_VARS) && !v->used_since_set) {
Eprint(tr("`%s' UNSET without being used (previous SET: %s:%d)"), str, v->filename, v->lineno);
}
DestroyValue(v->v);
hash_table_delete(&VHashTbl, v);
return OK;

View File

@@ -741,6 +741,8 @@ endif
set x 44
set x 45
set y 1000
unset y
EOF
# Make sure all the include files are ok

View File

@@ -24994,6 +24994,7 @@ TRANSLATE "Warning: Variable name `%.*s...' truncated to `%.*s'" ""
TRANSLATE "You have OMITted everything! The space-time continuum is at risk." ""
TRANSLATE "\\x00 is not a valid escape sequence" ""
TRANSLATE "`%%%c' substitution sequence should not be used without an AT clause" ""
TRANSLATE "`%s' UNSET without being used (previous SET: %s:%d)" ""
TRANSLATE "`%s' re-SET without being used (previous SET: %s:%d)" ""
TRANSLATE "did you mean" ""
TRANSLATE "here" ""
@@ -38717,6 +38718,7 @@ utctolocal(2050-11-06@04:00) => 2050-11-06@00:00
utctolocal(2050-11-06@07:00) => 2050-11-06@02:00
No reminders.
-stdin-(9): `x' re-SET without being used (previous SET: -stdin-:8)
-stdin-(11): `y' UNSET without being used (previous SET: -stdin-:10)
The following variables were set, but not subsequently used:
b - defined at -stdin-:2
x - defined at -stdin-:9