Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flash] abstract on haxe.ds.Vector<T> confuses Vector with Int #5093

Closed
YellowAfterlife opened this issue Apr 11, 2016 · 4 comments
Closed
Labels
platform-flash Everything related to Flash / SWF
Milestone

Comments

@YellowAfterlife
Copy link
Contributor

try.haxe | code:

import haxe.ds.Vector;
class Main {
    static function main() {
        new AbsVector<Int>(42);
    }
}

abstract AbsVector<T>(Vector<T>) {
    public function new(size:Int) {
        this = new Vector<T>(size);
        trace(this);
        trace(Std.is(this, Int));
        trace(this.length);
    }
}

outputs

Main.hx:11: 42
Main.hx:12: true
[Fault] exception, information=ReferenceError: Error #1069: Property length not found on Number and there is no default value.

which suggests that this = new Vector<T>(size) in the abstract's constructor somehow compiles into this = size.
What's going on?

@nadako
Copy link
Member

nadako commented Apr 11, 2016

Sounds like #4783

@Simn Simn added this to the 3.4 milestone Apr 11, 2016
@Simn Simn added the platform-flash Everything related to Flash / SWF label Apr 11, 2016
@Simn
Copy link
Member

Simn commented Apr 11, 2016

Right, I forgot about the Flash part of #4783. I know that using Vector with type parameters like that causes problems, but that error is still really strange.

@synek317
Copy link

It is even easier to reproduce without having to use abstract:
http://try.haxe.org/#6C006

How can it even happen?

@ncannasse
Copy link
Member

Ah right, it seems that Vector<KTypeParam> is compiled as Object by genSWF, which is normal for type safety (because the vectors are not compatible between them) but should throw an error when used with new because we don't know which vector class to construct.

function construct : 
	   0 this
	   1 scope
	   2 findpropstrict Object
	   3 reg 1
	   4 true
	   5 constructproperty Object 2
	   6 cast Object
	   7 setreg 2
	   8 findprop xxx
	   9 reg 2
	  10 initprop xxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-flash Everything related to Flash / SWF
Projects
None yet
Development

No branches or pull requests

5 participants