away3d / away3d-core-openfl

Away3D engine for OpenFL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Abstract UInt check causes error in Haxe 3.2

Type1J opened this issue · comments

https://github.com/away3d/away3d-core-openfl/blob/master/away3d/utils/Cast.hx#L50

I get:

away3d/utils/Cast.hx:50: characters 25-29 : Cannot use abstract as value

I'm not sure if Dynamic retains information about a value's abstract type, or just information on the underlying type. @Simn would probably be able to tell us for sure what information Dynamic really has for Std.is() calls.

I think this line could be commented out safely because the following line would still detect an UInt color.

That code is pretty horrible. For starters you cannot distinguish UInt and Int at run-time so that code never did anything to begin with. Then you cannot detect abstracts at run-time because they are a compile-time feature. Lastly that safe-cast is redundant, see http://haxe.org/manual/expression-cast-safe.html

@Greg209 For Haxe 3.2:

Please remove

if (Std.is(data, UInt)) return cast(data, UInt);

~line 50 in "away3d/utils/Cast.hx".

vv Optional from here down vv

The safe-cast is redundant, yes. It's not a "cast to" operator, it's a "Cast, and if you can't cast to this type that I give you, then throw." In this case, however, you would never throw because you already verified that the type is Int, and UInt is-a Int, so please change

if (Std.is(data, Int)) return cast(data, UInt);

~line 51 to

if (Std.is(data, Int)) return cast(data);

As for

if ((( cast(data, String) ).length == 6) && isHex(data)) return Std.parseInt("0x" + data);

~line 201, I believe that you can just

if ((data.length == 6) && isHex(data)) return Std.parseInt("0x" + data);

, but you may just want to make a

var str:String = cast(data);

somewhere in that block, which could produce better code on static platforms. (I don't know if it actually will, but it could.)

I'm pretty sure the people here would prefer a pull request over these ghetto patches. ;)

Yeah, I was just thinking that, but it was after I wrote the ghetto patch comment. If I have any more Haxe 3.2 issues, then I'll make a pull request, and I'll add all of the ghetto patches into it.

That would be great :)