Method Overloading - Why doesn't this work?

Let’s say I’ve got two methods overloaded like this:

Public Function Test(input as Integer) As Integer
  Return 1
End Function

Public Function Test(input as Integer) As String
  Return "STRING"
End Function

Then elsewhere I try:

var i as integer = Test(1)

It fails compiling with “There is more than one method with this name but this does not match any of the available signatures.”

I’m clearly trying to assign the output to an integer. Shouldn’t it be smart enough to know that since I’m requesting an integer it should use the integer-returning version of the method?

Xojo doesn’t detect different return values with overloading, so the error
use a variant as a return value if you need some method like this.

2 Likes

Thanks for that info, that is unfortunate. This may be worth a feature request.

I recall it has already been asked several times, it may be a huge work in the compiler as it is still not implemented.

1 Like