I was recently trying to get a function to return a UDT. I've since read that this is actually impossible - however, the DBP compiler seems to have no problem with the following syntax:
function myFunction() as Type
The following code indicates that the
as Type declaration is actually being applied to the last parameter of the function, even though the type name is outside the closing paren. The
print y line in
myFunction prints garbage.
type Rectangle
x as integer
y as integer
w as integer
h as integer
endtype
myFunction(255, 45)
yourFunction(255, 45)
wait key
end
function myFunction(x, y) as Rectangle
print x
print y
endfunction
function yourFunction(x, y) as integer
print x
print y
endfunction
Expected behavior: Type declarations after the closing paren shouldn't be applied to the last parameter. Instead, the compiler should warn that functions can't return user-defined types.