Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Regression of typeset output with "private"



On Fri, Feb 16, 2024 at 10:29 PM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Traced this to here:
>
> >> commit f99f7dca7552d21782354f675c0741896c9785f1
> >> Author: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
> >> Date:   Mon Oct 8 10:10:42 2018 +0100
> >>
> >>     43616: Various parameter setting and display fixes.
>
> in the context of explicitly asking for "typeset -p foo" it surely
> ought to print ... something?

How about this?  It skips PM_RO_BY_DESIGN for any parameter not
declared in the same scope where "typeset -p" is being run.  This
means that in addition to displaying parameters declared private,
it'll show cases where "local +h" has been used to shadow a special.

No doc included in this patch, but we should probably mention
somewhere that "typeset -p" no longer displays values for the special
parameters $!, $#, $-, $*, $@, $$, $?, $ARGC, etc. (unless "local +h"
per above)  This is actually a change in 5.9 vs. 5.8 that was not
included in the NEWS file.  Should it also be in the Doc?
diff --git a/Src/params.c b/Src/params.c
index a722a20f6..ee5733af4 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -6025,13 +6025,21 @@ printparamnode(HashNode hn, int printflags)
 	printflags |= PRINT_NAMEONLY;
 
     if (printflags & (PRINT_TYPESET|PRINT_POSIX_READONLY|PRINT_POSIX_EXPORT)) {
-	if (p->node.flags & (PM_RO_BY_DESIGN|PM_AUTOLOAD)) {
+	if (p->node.flags & PM_AUTOLOAD) {
 	    /*
 	     * It's not possible to restore the state of
 	     * these, so don't output.
 	     */
 	    return;
 	}
+	if (p->node.flags & PM_RO_BY_DESIGN) {
+	    /*
+	     * Compromise: cannot be restored out of context,
+	     * but show anyway if printed in scope of declaration
+	     */
+	    if (p->level != locallevel || p->level == 0)
+		return;
+	}
 	/*
 	 * The zsh variants of export -p/readonly -p also report other
 	 * flags to indicate other attributes or scope. The POSIX variants
diff --git a/Test/V10private.ztst b/Test/V10private.ztst
index 9eeda0f47..11ac92f03 100644
--- a/Test/V10private.ztst
+++ b/Test/V10private.ztst
@@ -328,6 +328,7 @@ F:future revision will create a global with this assignment
 F:See K01nameref.ztst up-reference part 5
 F:Here ptr1 finds private ptr2 by scope mismatch
 >typeset -n ptr1=ptr2
+>typeset -n ptr2
 *?*read-only variable: ptr2
 
  () {
@@ -348,10 +349,12 @@ F:See K01nameref.ztst up-reference part 5
 F:Here ptr1 finds private ptr2 by scope mismatch
 F:Assignment silently fails, is that correct?
 >typeset -n ptr1=ptr2
+>typeset -n ptr2=''
 >ptr1=ptr2
 >ptr1=
 >ptr2=
 >typeset -n ptr1=ptr2
+>typeset -n ptr2=''
 *?*no such variable: ptr2
 
  typeset ptr2
@@ -372,11 +375,13 @@ F:Assignment silently fails, is that correct?
 F:See K01typeset.ztst up-reference part 5
 F:Here ptr1 points to global ptr2 so assignment succeeds
 >typeset -n ptr1=ptr2
+>typeset -n ptr2
 >ptr1=ptr2
 >ptr2=val
 >ptr1=val
 >ptr2=val
 >typeset -n ptr1=ptr2
+>typeset -n ptr2
 >typeset ptr2=val
 
  () {


Messages sorted by: Reverse Date, Date, Thread, Author