Hi Andrew, I have seen this as well. As you say, we do already have the codegen for it, but the compiler is reading the js typedef swc that does not include this. I believe there is a need to change the original js typedefs (you sort of imagine that is like the playerglobal.swc, but for javascript instead of swf) to cover the argument variations for the as3 sort method signature variations. I did raise this same thing in the distant past as well, I can't remember what the answer was, but I am also keen to see this addressed....
On Wed, Feb 26, 2020 at 7:57 PM Frost, Andrew <[email protected]> wrote: > 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 > > >
