coderJeff wrote: ↑Jan 06, 2023 13:31
I will look at the case in fbc 1.10.0 to understand why is not allowed or if can be fixed.
The goal is that initializing tries to match the closest base. When matching the initializer to the UDT, first try is without up-casting, and if that fails, fall-back to a conversion. To make this work, we need to parse the entire initializer expression first and then find the best base.
So by default the initializer expression is parsed without allowing up-casting.
And because we are nested in a UDT parsing the initializers for the array elements doesn't allow up-casting. (I'm sure I had a note about allowing up-casting for array element initializers even when nested in a UDT, but I guess I lost it and forgot about it).
With a small fix to allow up-casting on array elements, the example from last post seems ok, but then we get a new issue (last case of y3):
Code: Select all
type parent
dim as integer i
end type
type child extends parent
dim as integer j
end type
type B
p1(0 to 0) as parent
p2 as parent
end type
dim y1 as B = type<B> _
( _ '' fbc 1.09 1.10
{ type<parent>(1) }, _ '' ok ok
type<parent>(3) _ '' ok ok
)
'' with fix-applied
dim y2 as B = type<B> _
( _ '' fbc 1.09 1.10
{ type<child>(1,2) } _ '' *bad ok
)
'' with fix-applied
dim y3 as B = type<B> _
( _ '' fbc 1.09 1.10
{ type<child>(1,2) }, _ ''
type<child>(3,4) _ '' *bad invalid data type
)
I'm trying to figure this last case out. I don't know if it is a simple detail missed, or will need major revisions.
----
I need to return to regular work next week, so I won't be starting any major revisions this weekend. I will try to understand the problem and update with a small fix, but if it is anything major, it will have to wait.