Actionscript compiler problem: error # 1068: Array and * cannot be matched

In my Flex (AS3) project, I get a very strange column.

Main Thread (Suspended: 
         VerifyError: Error #1068: Array and * cannot be reconciled.)

I was able to play it using this block of code. If you are debugging, you can never enter the crash function.

private var testArray:Array = [{},{},{}]

private function run():void {
  this.failure({});
}

private function failure(o:Object):void {
  for each(var el:Object in testArray) {
    o.ids = (o.ids||[]).concat(getArray());
  } 
}

private function getArray():Array {  return [Math.random()]; } 

When I run the program, this column is a single row, but this konal shows a big mess, as if it were a segmentation error:

> verify monkeyTest/failure()
>                         stack:
>                         scope: [global Object$ flash.events::EventDispatcher$
> flash.display::DisplayObject$
> flash.display::InteractiveObject$
> flash.display::DisplayObjectContainer$
> flash.display::Sprite$
> mx.core::FlexSprite$
> mx.core::UIComponent$
> mx.core::Container$
> mx.core::LayoutContainer$
> mx.core::Application$ monkeyTest$] 
>                          locals: monkeyTest Object? * * *   

Any suggestions? Greetings.

EDIT:

This code does not cause an error:

private function failure(o:Object):void {
      for each(var el:Object in testArray) {
        o.ids = o.ids || [];
        o.ids = o.ids.concat(getArray());
      } 
}
+3
source share
3 answers

The problem is here:

o.ids = (o.ids||[]).concat(getArray());

o.idsis a type *, and []- Array, therefore they cannot be compared

Change it to:

o.ids = ((o.ids as Array)||[]).concat(getArray());
+2

, ActionScript SWF . , , Adobe. (. ).

- , . .

EDIT: ​​, Glenn

+2

Source: https://habr.com/ru/post/1718353/


All Articles