Subject: Re: [BUG] functions can't create global readonly variables
From: Peter Stephenson <[email-masked]>
To: [email-masked]
Date: Sat, 2 Jan 2016 18:18:14 +0000
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Fri, 1 Jan 2016 20:27:10 -0800
Bart Schaefer <[email-masked]> wrote:
> 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

Bash is treating "typeset -r bar" differently from "readonly bar".
"readonly" affects any existing parameter or creates its own.
I think readonly is equivalent to "typeset -rg", so it stomps
on any existing global, too (unless it was already readonly).

We could make this optional behaviour for compatibility, possibly with
POSIX_BUILTINS which is a real ragbag of POSIX funnies.

pws