Hi all
Been a little while as I've been busy with AIR stuff, but we've also got a
Royale project ongoing and we have an issue which I'm hoping can be fixed by a
compiler update..
The issue is really simple so I'm slightly surprised we're hitting this:
var a : Array = [ "one", "two", "three" ];
a.sort(Array.DESCENDING);
trace(a);
This throws an ImplicitCoercionToUnrelatedTypeProblem
and results in:
Error: Implicit coercion of a value of type Number to an unrelated type
Function.
a.sort(Array.DESCENDING);
Presumably this is because the Array is a JavaScript class and it expects a
compare function as the only option. AS3's definition of Array takes an
optional number after the optional function (and is also very forgiving if you
then add in extra unused parameters after those two..), so valid calls would be:
sort(Number)
sort(Function)
sort(Function, Number)
sort(Function, Number, anything else ..)
i.e. the first argument must be a function or a number; if it' a function then
the second argument must be a number.
Note that there is code to actually handle the Array.sort() method and to check
for a numeric first argument: if this is the case then it gets turned into
Language.sort() - see FunctionCallEmitter.java.
So my question really is, how do we add in the extra function overload
definitions for this?
* is there a "proper" way that would ensure that the error isn't thrown by
ensuring that the function definition is correct in the first place? Perhaps
switching it to the AS3 definition of "function
sort(...<https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/statements.html#..._(rest)_parameter>
args):Array<https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html>"
?
* or, given we already have some hard-coded handling for this, would it be
okay to add a special case into the
MethodBodySemanticChecker.checkFunctionCall() method to handle this?
I would prefer the former but am not sure whether we can just override a Java
built-in definition, it's not quite the same as where we're adding missing
properties such as the Array.DESCENDING stuff within the typedefs..
If this can be done from there: can anyone remind me of the steps to take? I've
had a go at adding overrides to the "missing.js" file and then compiled the
typedefs using ant; no errors, and it had some "copying files" reported to the
compiler and royale-asjs projects. But I still get the same error..
Any thoughts appreciated!
thanks
Andrew