A type passed to the function signature in ProcPtr will not properly resolve the correct coerced type if using typeof() with some types. So far I've found constant length strings (string * 10 etc) and any type of pointer do not resolve correctly. Consider the following code:
function test overload (s as string) as string
return "string"
end function
function test overload (s as string ptr) as string
return "string ptr"
end function
function test overload (a as any ptr) as string
return "any ptr"
end function
function test overload (z as zstring ptr) as string
return "zstring ptr"
end function
function test overload (z as zstring ptr ptr) as string
return "zstring ptr ptr"
end function
type thing
dim x as integer
end type
dim x as string
dim y as string * 10
dim z as thing
dim a as zstring * 10
dim b as zstring ptr
print "Type coersion"
print ""
'Check that types can be coerced into one of the available test's
print test(x)
print test(y)
print test(@x)
print test(@y) 'Note this resolves to any ptr, not string ptr
print test(@z)
print test(a)
print test(b)
print test(@a)
print test(@b)
print ""
print "Typeof"
print ""
'Now check that they can be coerced through typeof
print ProcPtr(test, function(as typeof(@x)) as string)(0)
'print ProcPtr(test, function(as typeof(@y)) as string)(0) 'Does not resolve
'print ProcPtr(test, function(as typeof(@z)) as string)(0) 'Does not resolve
print ProcPtr(test, function(as typeof(@a)) as string)(0)
print ProcPtr(test, function(as typeof(@b)) as string)(0)
I would expect the lines that do not resolve to resolve to the string ptr variant (for @y) and the any ptr variant (@z) respectively.
It now makes sense to me that the fixed length string does not resolve to the "string" type, so strike that from the record. If anything it might just ought to resolve to zstring ptr. That's a discussion for another time though.
The pointer coercion issue still stands.
Related: [#650]
Which has to do with fbc's handling of typedefs that are pointers to fixed length strings.
Related
Bugs: #650