Comparison of Int and UInt might lead to unexpected results

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Comparison of Int and UInt might lead to unexpected results

Simon Krajewski
  Hello,

I was just checking out haxe 3D engines (haxe3d and the Sandy port) and
noticed that both contain examples that won't compile on current SVN due
to above error. Is it really necessary to stop compilation on this
error? I don't mind this being checked when using --flash-strict mode,
but not compiling it by default breaks quite a few as3 to haxe ports
that use this comparision.

On a releated question, mainly out of curiosity:

         var i = 0;
         var uint:UInt = 6;
         trace(i < uint);

Shouldn't i be inferred to UInt here? Seems to make more sense than
inferring it to Int and thus causing a compilation error.

Simon

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Comparison of Int and UInt might lead to unexpected results

Nicolas Cannasse
Le 30/01/2011 10:47, Simon Krajewski a écrit :
> Hello,
>
> I was just checking out haxe 3D engines (haxe3d and the Sandy port) and
> noticed that both contain examples that won't compile on current SVN due
> to above error. Is it really necessary to stop compilation on this
> error? I don't mind this being checked when using --flash-strict mode,
> but not compiling it by default breaks quite a few as3 to haxe ports
> that use this comparision.

These ports need to be fixed. They will most likely not work well as
soon as one of the two integers has a sign.

> On a releated question, mainly out of curiosity:
>
> var i = 0;
> var uint:UInt = 6;
> trace(i < uint);
>
> Shouldn't i be inferred to UInt here? Seems to make more sense than
> inferring it to Int and thus causing a compilation error.

The 0 value is an Int in haXe, sot it's already too late. Also, type
inference on UInt is not very easy to implement because it's declared as
typedef UInt = Int; Things will be more easy once we have true abstract
types.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Comparison of Int and UInt might lead to unexpected results

Simon Krajewski
  Am 30.01.2011 11:17, schrieb Nicolas Cannasse:
> The 0 value is an Int in haXe, sot it's already too late. Also, type
> inference on UInt is not very easy to implement because it's declared
> as typedef UInt = Int;

So UInt is typedeffed to Int, but cannot be compared to Int?

Simon

--
haXe - an open source web programming language
http://haxe.org