I have most of it working:

public function testEmptyListCoercion():void{
            var node:XML = <type type="without name
attribute"><val>2</val></type>;

            var list:XMLList = node.@name;

            var str:String = list;
            assertTrue(str == '');

            str = 'test'+list;
            assertTrue(str == 'test');

            var n:Number = Number(list); //WIP
            assertTrue(n == 0);

            n = 1+list;
            assertTrue(n == 1);

            var b:Boolean = Boolean(list);
            assertTrue(b === true);

            b = list || false;
            assertTrue(b === true);

            //non-empty coercion example
            list = node.val;
            n = 1+list; // this should be string concatentation ultimately
coerced to Number
            assertTrue(n === 12);
        }

Everything is passing there except for the
 var n:Number = Number(list);
marked WIP and I am close with that also. There was no need to use
XMLList.plus, but so far I am coercing xmlish and non-xmlish concatenation
with String(xmlish) (and not with Language.string which triggers valueOf).
I guess I need to check more complex concatenations with 3 or more elements
being added as well.

I will try to get it in tomorrow before I start my normal work hours.



On Tue, Jul 5, 2022 at 8:49 AM Greg Dove <greg.d...@gmail.com> wrote:

>
> I will look into it today.
>
> Unfortunately the instance level 'plus' method is not suitable for the
> general case, because an XMLList reference can also be null which would
> cause an error in the generated js code that would not be present in AVM,
> although this is an edge case. But it does mean that for the general case,
> if there is not native support via valueOf or toString etc, then it is
> better to route things through a static method that covers the edge cases.
>
>
>
>
>
>
>
>
> On Tue, Jul 5, 2022 at 8:26 AM Harbs <harbs.li...@gmail.com> wrote:
>
>> It looks like BinaryOperatorEmitter is supposed to be emitting .plus(),
>> but it doesn’t seem to be doing so…
>>
>> Harbs
>>
>> > On Jul 4, 2022, at 6:32 PM, Harbs <harbs.li...@gmail.com> wrote:
>> >
>> > The logic should be something like this in pseudocode:
>> >
>> > if(isPlus && (isXMLish(righthand) || isXMLish(leftHand){
>> > if(isXM<Lish(leftHand){
>> > //output lefthand.plus(righthand)
>> > }else{
>> > // output righthand.plus(lefthand)
>> > }
>> >
>> >> On Jul 4, 2022, at 6:25 PM, Harbs <harbs.li...@gmail.com <mailto:
>> harbs.li...@gmail.com>> wrote:
>> >>
>> >> I think the compiler should be using the “plus” XML method for string
>> concatenation of XML.
>> >>
>> >>> On Jul 4, 2022, at 5:36 PM, Greg Dove <greg.d...@gmail.com <mailto:
>> greg.d...@gmail.com>> wrote:
>> >>>
>> >>>  (it does equal undefined), but it
>> >>> seems it does concatenate as an empty string.
>> >>
>> >
>>
>>

Reply via email to