Menu

#984 Incorrect syntax for a member array passed as argument to a procedure

closed
nobody
None
compiler
2023-09-17
2023-07-14
No

The problem concerns any member array passed as an argument to a procedure:

  • (1) either in addition to the correct syntax a second erroneous syntax works (for any type of member array, except for procedure pointers),
  • (2) or only the erroneous syntax works (for a member array of procedure pointers).

Example for the case (1):

Type UDT
    Dim As Integer array(10)
End Type

Sub test(array() As Integer)
    Print array(5)
End Sub

Dim As UDT u
u.array(5) = 1234

Dim As Integer array(10)
array(5) = 5678

test(u.array())   '' 1234 : OK
test(u.array(0))  '' 1234 : but should be NOK because Type mismatch
test(u.array(5))  ''    0 : but should be NOK because Type mismatch
test(array())     '' 5678 : OK
'test(array(1))   '' Type mismatch : OK
'test(array(5))   '' Type mismatch : OK

Sleep

Example for the case (2):

sub test(inParam() as sub (byval x as integer))
    inParam(0)(3)
end sub

sub thing(byval x as integer)
    print x
end sub

type udt
    dim arr(10) as sub (byval as integer)
end type

dim udtPtr as udt ptr
udtPtr = new udt
udtPtr->arr(0) = @thing

dim udtInst as udt
udtInst.arr(0) = @thing

'Basic array
dim arr(10) as sub (byval as integer)
arr(0) = @thing

test(arr())          '' 3 : OK
'test(udtInst.arr()) '' NOK : syntax error but should work
'test(udtPtr->arr()) '' NOK : syntax error but should works
test(udtInst.arr(0)) '' 3 : works but should be NOK because type mismatch
test(udtPtr->arr(0)) '' 3 : works but should be NOK because type mismatch

sleep
delete udtPtr

This bug report is issued from forum:
https://www.freebasic.net/forum/viewtopic.php?t=32304

Related

Feature Requests: #285

Discussion

  • fxm (freebasic.net)

    If the member array is static, the wrong syntax is no more allowed:

    • either only the correct syntax works (for any type of member array, except for procedure pointers),
    • or no syntax works (for a member array of procedure pointers).
     

    Last edit: fxm (freebasic.net) 2023-07-14
  • Jeff Marshall

    Jeff Marshall - 2023-09-17
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB