summaryrefslogtreecommitdiff
path: root/Src/Modules/param_private.c
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2023-02-12 11:21:23 -0800
committerBart Schaefer <schaefer@zsh.org>2023-02-12 11:21:23 -0800
commit511e020c68955f737036b7febd360615517a3637 (patch)
tree32674f5c1af114622f81bd30b82cd74b02db9f8a /Src/Modules/param_private.c
parentd3edf318306e37d2d96c4e4ea442d10207722e94 (diff)
downloadzsh-511e020c68955f737036b7febd360615517a3637.tar.gz
zsh-511e020c68955f737036b7febd360615517a3637.zip
51360: Initial implementation of named references.
Diffstat (limited to 'Src/Modules/param_private.c')
-rw-r--r--Src/Modules/param_private.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/Src/Modules/param_private.c b/Src/Modules/param_private.c
index 065fa63d2..70f36ceb1 100644
--- a/Src/Modules/param_private.c
+++ b/Src/Modules/param_private.c
@@ -512,9 +512,16 @@ static GetNodeFunc getparamnode;
static HashNode
getprivatenode(HashTable ht, const char *nam)
{
- HashNode hn = getparamnode(ht, nam);
+ /* getparamnode() would follow namerefs, we must not do that here */
+ HashNode hn = gethashnode2(ht, nam);
Param pm = (Param) hn;
+ /* autoload has precedence over nameref, so getparamnode() */
+ if (pm && (pm->node.flags & PM_AUTOLOAD)) {
+ hn = getparamnode(ht, nam);
+ pm = (Param) hn;
+ /* how would an autoloaded private behave? return here? */
+ }
while (!fakelevel && pm && locallevel > pm->level && is_private(pm)) {
if (!(pm->node.flags & PM_UNSET)) {
/*
@@ -533,6 +540,12 @@ getprivatenode(HashTable ht, const char *nam)
}
pm = pm->old;
}
+
+ /* resolve nameref after skipping private parameters */
+ if (pm && (pm->node.flags & PM_NAMEREF) &&
+ (pm->u.str || (pm->node.flags & PM_UNSET)))
+ pm = (Param) resolve_nameref(pm, NULL);
+
return (HashNode)pm;
}
@@ -571,7 +584,7 @@ printprivatenode(HashNode hn, int printflags)
static struct builtin bintab[] = {
/* Copied from BUILTIN("local"), "P" added */
- BUILTIN("private", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_private, 0, -1, 0, "AE:%F:%HL:%PR:%TUZ:%ahi:%lmprtux", "P")
+ BUILTIN("private", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_private, 0, -1, 0, "AE:%F:%HL:%PR:%TUZ:%ahi:%lnmprtux", "P")
};
static struct features module_features = {