Hi Harbs,

I am keen to help find an easier solution.

@royalesuppresscompleximplicitcoercion  crypto.createDecipher

or for non-specific suppression, simply:
@royalesuppresscompleximplicitcoercion  true
or even
@royalesuppresscompleximplicitcoercion
(which defaults to 'true')

is another option, any of the above does not require writing the extra 'as'
code and then ignoring it. So it is only one addition instead of two. But
it obviously still requires some effort and would be better if that was not
needed.

I assume you want (as would I) something more automatic or something that
is recognizable in the typedefs to prevent this problem at all in these
cases.
I have not done anything with  typedefs yet, and need to look into that
more to learn about how they work and to see how the definitions may be
recognized in the compiler as being different, such as whether they can
have their own metadata or something distinctive like that.

I can understand why it is causing an issue in this case:
'The crypto.createDecipher() or crypto.createDecipheriv() methods are used
to create Decipher instances. Decipher objects are not to be created
directly using the new keyword.'

But I don't understand your statement that 'Constructors for typedefs will
**always** be undefined because they don’t exist at runtime'
Don't we also have many typedefs that represent normal constructors too?
For example, all the native javascript types - aren't these sort of like
playerglobal.swc is for avm?

if I do:
var array:Array = [new Map()]
var myMap:Map = array[0];

I think that should work as an implicit coercion. But, like I said, maybe I
am showing my ignorance in terms of what you mean by typedefs.
I will try to get my head into the typedefs side of things next week, to
understand more.




On Mon, Jun 24, 2019 at 9:59 PM Harbs <harbs.li...@gmail.com> wrote:

> I have the following code in an app which uses Node.js:
>
> var cr:* = require('crypto');
> var decipher:Decipher = cr.createDecipher('aes-256-ctr',KEY);
>
> (The reason cr is untyped is because crypto.createDecipher is not
> recognized in the typedefs.)
>
> This used to work fine, but it currently gets compiled as:
>
>   var /** @type {*} */ cr = require('crypto');
>   var /** @type {crypto.Decipher} */ decipher = /* implicit cast */
> org.apache.royale.utils.Language.as(cr["createDecipher"]('aes-256-ctr',
> com.printui.utils.PrefUtils.KEY), crypto.Decipher, true);
>
> The Language.as cast fails because the rightOperand.constructor is
> undefined. Constructors for typedefs will **always** be undefined because
> they don’t exist at runtime, so implicit casts on typedef types like this
> will always fail.
>
> Presumably, I can use:
> var decipher:Decipher = cr.createDecipher('aes-256-ctr',KEY) as Decipher;
> and it’ll work as long as I ignore as coercions as a compiler option, but
> this feels like a step backwards.
>
> Thoughts?
> Harbs

Reply via email to