It appears SETLOCAL/ENDLOCAL does not remove the SETARRAY created within it.
Since SET is used to both modify the environment and to modify array elements, I had expected the array to have been treated as part of the environment saved by SETLOCAL, which also includes aliases and functions. My preference is for the ENDLOCAL to remove any array variables created after the SETLOCAL. However, the documentation for the xARRAY and xLOCAL commands does not say one way or the other. What is supposed to happen? Do we need this check before every SETARRAY?
C:\>ver TCC 16.01.45 Windows 7 [Version 6.1.7601] C:\>echo %@arrayinfo[TestA] -1 C:\>setlocal C:\>setarray TestA C:\>endlocal C:\>echo %@arrayinfo[TestA] 1 C:\>setarray TestA TCC: Array variable is already defined "TestA"
if %@arrayinfo[ArrayName] NE -1 unsetarray ArrayName