Hi Andrew, IIRC, there are a few places where we've already edited the JS definition, which is why the typedefs use custom versions of Google Closure's externs instead of externs directly from their repo.
So I think it is just a matter of editing: https://raw.githubusercontent.com/royale-extras/closure-compiler/royale/externs/es3.js which I believe comes from https://github.com/royale-extras/closure-compiler/blob/master/externs/es3.js If we change the parameter for Array.sort to the AS parameter list to (... args) instead of Function, then the final Array.as in royale-typedefs/js should allow anything there, and FunctionCallEmitter.java can pick up the extra cases and MethodBodySemanticChecker should not complain. I think Harbs owns that repo and can update that file. -Alex On 2/25/20, 10:58 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://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhelp.adobe.com%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2Fstatements.html%23..._(rest)_parameter&data=02%7C01%7Caharui%40adobe.com%7C8bc49bc1e3da4ce469f508d7ba893372%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C637182970796966183&sdata=7t7BJmqI4yGxB9AO45fBcFqxzaQDgrlE%2B8pXSaycXvU%3D&reserved=0> args):Array<https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fhelp.adobe.com%2Fen_US%2FFlashPlatform%2Freference%2Factionscript%2F3%2FArray.html&data=02%7C01%7Caharui%40adobe.com%7C8bc49bc1e3da4ce469f508d7ba893372%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C637182970796966183&sdata=rhCeq4hc2LK4QpBs2lY%2F%2FHPQo%2FZ0AUM3gxXSgNMK9JI%3D&reserved=0>" ? * 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
