Hi

Thanks - so that looks like a good approach. I've just had a quick go at trying 
to hack this (the closure compiler jar file has a zip that contains this es3.js 
file..) but no joy so it looks like it needs to be built properly.

If I was just to build that closure compiler (properly), and put the resulting 
JAR file into royale-asjs/js/lib/google/closure-compiler/compiler.jar, should 
that be sufficient? .. it doesn't actually seem like that jar file is being 
loaded at all when I compile, I've just renamed two folders:
C:\Work\Royale\royale-asjs\js\lib\google
so I no longer have "closure-compiler" or "closure-library", and I'm still 
getting it building (and failing):

>c:\work\Royale\royale-asjs\js\bin\mxmlc TestArray.mxml
Using Royale Compiler codebase: c:\Work\Royale\royale-asjs\js\bin\..\..
Using Royale SDK: c:\Work\Royale\royale-asjs\js\bin\..\..
MXMLJSC
-sdk-js-lib=c:\Work\Royale\royale-asjs\js\bin\..\..\frameworks\js\Royale\generated-sources
TestArray.mxml
C:\...\TestArray.mxml(20): col: 14 Error: Implicit coercion of a value of type 
Number to an unrelated type Function.
      a.sort(Array.DESCENDING);

There's no such folder as the one being passed in to sdk-js-lib, don't know 
where that comes from but no 'Royale' folder under frameworks\js..

So basically - once the closure compiler is updated, what happens next in order 
to get these definitions to be recognised within Royale?!


thanks

   Andrew


-----Original Message-----
From: Alex Harui <[email protected]> 
Sent: 26 February 2020 07:29
To: [email protected]
Subject: [EXTERNAL] Re: Array sort with numeric argument

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://clicktime.symantec.com/3AafESw7XFxpnySNpTYup3L7Vc?u=https%3A%2F%2Fraw.githubusercontent.com%2Froyale-extras%2Fclosure-compiler%2Froyale%2Fexterns%2Fes3.js
which I believe comes from
https://clicktime.symantec.com/3wUnMy1wgiKftPWEeyrXBx7Vc?u=https%3A%2F%2Fgithub.com%2Froyale-extras%2Fclosure-compiler%2Fblob%2Fmaster%2Fexterns%2Fes3.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://clicktime.symantec.com/3UhYNbMDsk619zEbD94SWgU7Vc?u=https%3A%2F%2Fnam04.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fhelp.adobe.com%252Fen_US%252FFlashPlatform%252Freference%252Factionscript%252F3%252Fstatements.html%2523..._%28rest%29_parameter%26data%3D02%257C01%257Caharui%2540adobe.com%257C8bc49bc1e3da4ce469f508d7ba893372%257Cfa7b1b5a7b34438794aed2c178decee1%257C0%257C0%257C637182970796966183%26sdata%3D7t7BJmqI4yGxB9AO45fBcFqxzaQDgrlE%252B8pXSaycXvU%253D%26reserved%3D0>
 
args):Array<https://clicktime.symantec.com/3qLbn7V3BiNf2ARiZqYA1G7Vc?u=https%3A%2F%2Fnam04.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fhelp.adobe.com%252Fen_US%252FFlashPlatform%252Freference%252Factionscript%252F3%252FArray.html%26data%3D02%257C01%257Caharui%2540adobe.com%257C8bc49bc1e3da4ce469f508d7ba893372%257Cfa7b1b5a7b34438794aed2c178decee1%257C0%257C0%257C637182970796966183%26sdata%3DrhCeq4hc2LK4QpBs2lY%252F%252FHPQo%252FZ0AUM3gxXSgNMK9JI%253D%26reserved%3D0>"
 ?
      *   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
    
    
    

Reply via email to