My observation below...
On 05/26/2014 09:10 AM, Dan Douglas wrote:> Hi,
When I increment an uninitialized element of an indexed or associative array
from within an arithmetic context, there is no effect in the latest alpha. It
worked in ksh93u. It applies only to arithmetic assignments, but incrementing
via simple assignment works fine.
Can anyone reproduce this regression?
$ ksh -c 'print -v .sh.version'
Version AIJM 93v- 2014-05-09
# Increment from math context broken.
$ ksh -c 'integer i; integer -a arr; ((i++, arr[3]++)); typeset -p arr
i'
typeset -a -l -i arr=()
typeset -l -i i=1
There are two things at work here.
One: we're working with unitialised variables. What do the standards
actually say about this? (I will be looking this up).
Two: The regression appears to be constrained to 'typeset -p', which I'm
unlikely to use in a script.
Here's my output. Note that if I uncomment the 'set -e -u' in line [5],
the script does not proceed past [9]:
[5]:~/src/ksh-regression 74 $ PS4='+[$LINENO] '
../ast/arch/linux.i386\-64/bi>
Version AIJM 93v- 2014-01-14
+[5] : set -e -u
+[6] typeset -li i
+[7] typeset -li -a arr
+[8] ((i++))
+[9] ((arr[3]++))
+[10] test 1 -eq 1
+[11] test 1 -eq 1
+[12] : '${arr[3]}=1' expects 1
+[13] typeset -p arr
typeset -a -l -i arr=()
Note how typeset -p appears to contradict the results
of lines [11] and [12].
And here's the code for easy copy/paste:
print -v .sh.version
function increment_from_math_context {
: set -e -u
integer i
integer -a arr
((i++))
((arr[3]++)) # Fails when -u set
(test ${arr[3]} -eq 1)
(test ${i} -eq 1)
: '${arr[3]}'=${arr[3]} expects 1
typeset -p arr
}
typeset -tf increment_from_math_context
increment_from_math_context
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers