Hi Antonio,
atlopes wrote: Just to clarify, what I questioned was the decision to perform that conversion in particular over others that could be possible.
Understood, but the conversion is not a problem, the problem is that the compiler could not know which overload to call. When you had only those two typed overloads:
FUNCTION BITNOT (n AS INT)
FUNCTION BITNOT (b AS Binary)
and you called it with
BITNOT(any_untyped_var)
then the compiler does not know which one of the two to use. Currently it uses the first one, although there is not really a reason to assume that this one is the intended one (or not). Assuming that the compiler did the right thing by using one of those overloads, then it is also correct to emit code that converts the untyped var value into an INT (the type expected from the function). The conversion is correct, what is wrong is that the compiler did pick one of the two functions, instead of stopping compilation and throwing a compiling error message instead.
atlopes wrote: I'd prefer to have and keep the overloads for typed arguments. Not only this would reward future code, but it also rewards current VFP typed source code (there is such a thing!).
Do you mean typing a LOCAL with "AS"? From what I see, in VFP you can do
LOCAL n AS Integer
n := "Let's put a string in an Integer variable

"
? n
and that runs with no errors, so it is not typed really. Or do you mean with a different way?
atlopes wrote: A final note: I could not reproduce the by reference vs. by value point I mentioned above outside the implementation of BITNOT(). Nevertheless, I think that the behavior is verifiable. Hopefully, it's just something I'm overlooking.
No you're right, there's an issue here. The Binary type itself is a STRUCTURE (so it's being passed by value), but it holds its data internally in a byte array (so a reference type) and when you convert the Binary value into a BYTE array in your first local assignment, then the conversion returns that exact internal array. Maybe the best way is to return a new copy of the array instead, will log an incident on that to be looked at.
For now, you can change such code to
LOCAL Source := BinString AS BYTE[]
LOCAL Result := BYTE[]{Source:Length} AS BYTE[]
System.Array.Copy(Source, Result, Source:Length)
although it probably makes more sens to do this same thing in the X# runtime instead.