Hmmm... What happens now is that the
ary() within
fn'test1() acts like a
dimx array that has not yet been initialized. But you're not currently allowed to do much of anything with an uninitialized
dimx array, besides get the
.extent() of it. And the compiler can't tell if an array has been initialized, since it depends on the
dimx statement being executed. (It knows the array's type from having seen the
dimx statement during compilation, but it can't know if it has been executed.)
The end result in terms of runtime behavior that you're looking for would be something like this:
FUNCTION fn'test1(ary()=.NULL as TEST_STRUCT) as f8
Trace.Print "1: "+.EXTENT(ary())
if .extent(ary()) < 0 then
.fn = fn'test2()
else
.fn = fn'test2(ary()=ary())
endif
ENDFUNCTION
So maybe the solution is to have the runtime system detect the attempt to pass the uninitialized array and just remove the parameter entirely from the calling parameter list (logically equivalent to the example above) but integrated into the call directly.
No matter what it's going to require an update, but I'm not completely sure whether it can be just a runtime update or a compiler update. One possible concern is that if the called function doesn't declare a default value for the received array and instead uses
.argcnt to determine whether the argument was passed, then having the runtime system automatically remove the passed parameter in the case of an uninitialized array might lead to further confusion. The issue is probably moot here since currently the attempt to pass the uninitialized array will generate an error immediately, before the called function would have a chance to use
.argcnt, but I'm not sure I've thought through all the permutations. Let me ponder it a bit.