Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Invalid cast inserted in abstract call #2713

Closed
Simn opened this Issue · 11 comments

3 participants

@Simn
Owner
abstract Vector<T>(Array<T>) {

    public function new ():Void {
        this = new Array<T>();
    }

    public function push(x:T):Int {
        return this.push(x);
    }

    @:from static public inline function fromArray<T, U> (a:Array<U>):Vector<T> {
        return cast a;
    }

    @:to public function toArray<T>():Array<T> {
        return this;
    }
}

class Main {
    static public function main() {
        var v:Vector<Int> = [1, 2, 3];
        for (i in 0...9) {
            v.push(i);
        }
        trace(v);
    }
}

On the v.push call the compiler inserts a cast of the this argument to Array<T>, which is nonsense.

@Simn Simn self-assigned this
@Simn
Owner

This is another regression. Looks like we can expect 3.1.1 by the end of the week. :)

@Simn Simn closed this in 22e5a8f
@delahee
@Simn
Owner

I don't think so, this should only happen between abstracts and their underlying type.

@Simn
Owner

This fails horribly on As3:

Issue2713.hx:30: 1 should be [1,2,3]
Issue2713.hx:31: 2 should be 0
Issue2713.hx:32: 3 should be 1
Issue2713.hx:33: 0 should be null
Issue2713.hx:34: 1 should be null
@Simn Simn reopened this
@nadako
Collaborator

Issue2713.hx:30: 1 should be [1,2,3] what?:)

@Simn
Owner

We generate var v : Array = Array([1,2,3]);, which is a constructor call instead of a cast. I don't know why we aren't simply using as in all cases.

@Simn
Owner

Changing that I get TestSerialize.hx:30: 1900-02-28 00:00:00 should be 2014-03-05 18:44:59. Eh...

@nadako
Collaborator

Type(value) is a cast on as3 in general. Maybe for Array it's different though.

@Simn
Owner

mxmlc had this to say about the matter:

Array(x) behaves the same as new Array(x).  To cast a value to type Array use the expression x as Array instead of Array(x).

                        var v : Array = Array([1,2,3]);
@nadako
Collaborator

So Array is special. This is probably ECMA-compatibility related stuff, we should check if there's other cases (i think Vector is a function as well). Or just use "as", but what's the deal with date serialization then?

@Simn Simn closed this in 373de26
@Simn
Owner

I have no idea, and I don't think I want to find out either. I've changed genas3 to generate x as Array now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.