fbc icon indicating copy to clipboard operation
fbc copied to clipboard

Parsing error with var-len arrays in UDT

Open mudhairless opened this issue 3 years ago • 1 comments

Issue is present in both 32 and 64 bit compilers with versions 1.09.0, 1.08.1, and 1.07.3 known affected.

Error message from compiler: fbc-issue.bas(10) error 3: Expected End-of-Line, found '.' in 'redim test(0,0).array(0)'

I have only tested this on Windows but it should not differ between platforms.

type aType
    array(any) as integer
end type
 
dim test(any,any) as aType

redim test(0,0)

'doesnt work
redim test(0,0).array(0)

'works
redim (test(0,0).array)(0)

mudhairless avatar Feb 06 '22 19:02 mudhairless

Some related information: This sounds to me like it's the classic redim parsing issue. Since it can be used to declare variables, there needed to be some differentiation between redim id(... and redim expression.... So I think redim test(0,0) looks like a variable declaration and the parser simply doesn't look-ahead far enough to see the .array(0) following behind it which could be used to indicate that it's actually an expression.

On the one hand, it doesn't have infinite look-ahead (if I remember correctly), on the other hand it can't really parse an expression it it's an array declaration, because the symbol isn't defined yet, (lower to upper) isn't valid in expressions, etc. It would be quite a challenge to try and work-around that. I remember using the extra parentheses as in redim (expression) to avoid the issue.

dkl avatar Oct 03 '22 14:10 dkl