Code: Select all
function test overload (i as integer ptr) as integer
return 100
end function
function test overload (s as string ptr) as integer
return 999
end function
dim x as integer
dim y as string
dim funcPtrx as function(as typeof(@x)) as integer = @test
dim funcPtry as function(as typeof(@y)) as integer = @test
print funcPtrx(@x)
print funcPtry(@y)
Code: Select all
...
dim funcPtrA as function(as any ptr) as integer = cast(function(as any ptr) as integer, funcPtrx)
dim funcPtrB as function(as any ptr) as integer = cast(function(as any ptr) as integer, funcPtry)
print funcPtrA(0)
print funcPtrB(0)
Code: Select all
function test overload (i as const integer ptr) as integer
return 100
end function
function test overload (s as string ptr) as integer
return 999
end function
dim x as integer
dim y as string
dim funcPtrx as function(as typeof(@x)) as integer = @test
dim funcPtry as function(as typeof(@y)) as integer = @test
'Is there a way to directly assign the string variant of "test" using cast?
dim funcPtrA as function(as any ptr) as integer = cast(function(as typeof(@y)) as integer, @test)
print funcPtrx(@x)
print funcPtry(@y)
print funcPtrA(0) 'Prints the wrong output, should be 999
In playing around with it I'm starting to think this is a bug. The compiler should be able to recognize that the cast is attempting to specify the function signature but isn't doing so.