Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Invalid cast inserted in abstract call #2713

Closed
Simn opened this Issue Mar 5, 2014 · 11 comments

Comments

Projects
None yet
3 participants
Owner

Simn commented Mar 5, 2014

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 Mar 5, 2014

Owner

Simn commented Mar 5, 2014

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

@Simn Simn closed this in 22e5a8f Mar 5, 2014

Contributor

delahee commented Mar 5, 2014

Would it be related to my vector that becomes an Int during ctor thing ?
Le 5 mars 2014 18:19, "Simon Krajewski" notifications@github.com a écrit :

Closed #2713 #2713 via
22e5a8fhttps://github.com/HaxeFoundation/haxe/commit/22e5a8f044430a184cef27f7555234e7f8a3f739
.


Reply to this email directly or view it on GitHubhttps://github.com/HaxeFoundation/haxe/issues/2713
.

Owner

Simn commented Mar 5, 2014

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

Owner

Simn commented Mar 5, 2014

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 Mar 5, 2014

Owner

nadako commented Mar 5, 2014

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

Owner

Simn commented Mar 5, 2014

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.

Owner

Simn commented Mar 5, 2014

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

Owner

nadako commented Mar 5, 2014

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

Owner

Simn commented Mar 5, 2014

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]);
Owner

nadako commented Mar 5, 2014

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 Mar 5, 2014

Owner

Simn commented Mar 5, 2014

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