this is an interesting issue...
it remembers me
the issue and the bug that I found in Qbasic about DEF FN.
https://www.qb64.org/forum/index.php?topic=2524.msg117972#msg117972I admit that I never have used DEF FN in Qbasic in my programs. Yes I know it theorically, but never I used it in a real program.
Nevertheless I tried to make a tool to convert old DEF FN of QB/QBasic into FUNCTION of QB64. But for my lackness of knowledge I thought DEF FN as a separate block of code not so different from FUNCTION or SUB. What a dumbness!! DEF FN is like a GOSUB RETURN block of code so it is a piece of the main module. To complete my tool I need to develope a parser to find the variables declared into DEF FN and the variables of the main that DEF FN uses because all these must be SHARED to not break the link of code!.
Why is it matter with your experience?
Reading your code I have thought that there is no problem because in a flow of program from the high to the bottom and from left to the right of lines of source code the line
has been executed after the declaration
'=======
SetLevel:
'=======
and all these lines are in the main module... so why does the parser understand pdata$(1,1) ="x" as a different array variable with declaration and initialization in the same line of code?
The answer is: it is possible that the lines of source code are managed and changed during the compiling process and so the line IF pdata$(1,1) = "x" THEN is processed before the line REDIM pdata$(10,10).
This is the same that happens in QBasic with this code
FnQbasicBug= z% * a%
a% = 10
So we can affirm that this is another gift that QB64 has eredited from QB/Qbasic and it happens to duplicate the way of working of Qbasic.