SWAP with base-type and derived-type doesn't give an error when is in this order:
'Swap base_type_instance, derived_type_instance'
But the reverse order ('Swap derived_type_instance, base_type_instance'), gives the expected error (error 20: Type mismatch).
This looks as if 'Swap' was error-processed as the operator '=':
'base_type_instance = derived_type_instance' OK
'derived_type_instance = base_type_instance' NOK (error 164: Invalid assignment/conversion)
Type Parent
Dim I As Integer
End Type
Type Child Extends Parent
Dim J As integer
End Type
Dim p As Parent, c As Child
p = c ' OK
'c = p ' NOK: error 164: Invalid assignment/conversion in 'c = p'
Swap p, c ' should be NOK as below
'Swap c, p ' NOK: error 20: Type mismatch in 'Swap c, p'
Same behavior for base-type pointer and derived-type pointer.
Referring to post at:
http://www.freebasic.net/forum/viewtopic.php?p=177222#p177222
and following.
SWAP will now check not only whether l = r would work, but also whether r = l would work. That way it can be "inheritance-aware" now, but it really should have done the check that way from the beginning.