Subject: Re: [BUG] functions can't create global readonly variables
From: Bart Schaefer <[email-masked]>
To: [email-masked]
Date: Fri, 1 Jan 2016 20:27:10 -0800
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Jan 2,  4:27am, Martijn Dekker wrote:
}
} It is apparently impossible to create global readonly variables from
} within a function.

    typeset -gr var=value
or
    readonly -g var=value

} I don't know if this is intended behaviour for native zsh mode; the
} 'zshbuiltins' man page does not mention anything about this.

Of course it does:

    readonly
	 Same as typeset -r.

    typeset ...
	 Set or display attributes and values for shell parameters.

	 A parameter is created for each NAME that does not already refer
	 to one.  When inside a function, a new parameter is created for
	 every NAME (even those that already exist), and is unset again
	 when the function completes.

} But it is certainly a bug for POSIX/'emulate sh' mode.

I think it's undefined behavior for POSIX/'emulate sh'.  Certainly bash
agrees with us:

$ foo() { typeset -r bar; typeset -p bar; }
$ foo
declare -r bar
$ typeset -p bar
bash: typeset: bar: not found