zsh-workers
 help / color / mirror / code / Atom feed
* array bug
@ 1999-11-14  2:45 Dave Gaulke
  1999-11-14 17:09 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Gaulke @ 1999-11-14  2:45 UTC (permalink / raw)
  To: zsh-workers

I found a problem with arrays used inside a function.  I'm running zsh 3.1.6
on Solaris 2.6.  Here's a function that demonstrates the problem.

function arrtest
{
	set -A myarray
	typeset -x myarray
	myarray[1]=arrtest
	print ${myarray[1]}
}

When I run this it prints only "a" and not the expected "arrtest".  If I run
this outside of a function it works properly.  Also if I reverse the order of
the first two lines of the function it works properly.

Dave
-- 
+----------------------------------------------------+
|   Dave Gaulke           email: gaulke@lucent.com   |
|   Lucent Technologies   voice: 303.538.5168        |
|   11900 N. Pecos St.      fax: 303.538.6697        |
|   Denver, CO  80234                                |
+----------------------------------------------------+


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: array bug
  1999-11-14  2:45 array bug Dave Gaulke
@ 1999-11-14 17:09 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 1999-11-14 17:09 UTC (permalink / raw)
  To: Dave Gaulke, zsh-workers

On Nov 13,  7:45pm, Dave Gaulke wrote:
} Subject: array bug
}
} function arrtest
} {
} 	set -A myarray
} 	typeset -x myarray
} 	myarray[1]=arrtest
} 	print ${myarray[1]}
} }
} 
} When I run this it prints only "a" and not the expected "arrtest".

This is not the bug you think it is.

"set -A myarray" is declaring a *global* (not local to "arrtest") array
named "myarray".  It's exactly equivalent to writing

	myarray=()

"typeset -x myarray" then declares a local scalar, also named "myarray",
which hides the global.  This is a result of a recent change that makes
"export" equivalent to "typeset -gx" and not equivalent to "typeset -x".
This is a known bug.  For the time being, you should use "export" when
you mean "export".

    function arrtest
    {
    	set -A myarray
	export myarray
	myarray[1]=arrtest
	print $myarray
    }

However, since arrays can't be exported in the first place (zsh marks
them exported internally, but does not put them in the environment) it's
almost certainly the case that you shouldn't have used "typeset -x" in
the first place.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-11-14 17:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-14  2:45 array bug Dave Gaulke
1999-11-14 17:09 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).