[js] Equality bug?

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

[js] Equality bug?

Viktor Hesselbom-2
Hello!

Not sure if this is considered a bug or correct behavior. When targeting JavaScript and comparing an int and a string with the "same value" haXe outputs it as a match.

Look at this example:

var a = [4, "4"];
trace (a[0] == a[1]); // true
trace (untyped __js__("a[0] == a[1]")); // true
trace (untyped __js__("a[0] === a[1]")); // false

What do you think?

Best,
Viktor

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

Re: [js] Equality bug?

alexander.konotop
В Mon, 12 Sep 2011 15:36:43 +0200
Viktor Hesselbom <[hidden email]> пишет:

> Hello!
>
> Not sure if this is considered a bug or correct behavior.
> When targeting JavaScript and comparing an int and a string with the
> "same value" haXe outputs it as a match.
>
> Look at this example:
>
> *var a = [4, "4"];*
> *trace (a[0] == a[1]); // true*
> *trace (untyped __js__("a[0] == a[1]")); // true*
> *trace (untyped __js__("a[0] === a[1]")); // false*
>
> What do you think?
>
> Best,
> Viktor

==  => same value
=== => same value and same type
4   => int
"4" => string

P.S. I didn't know that HaXe has "===" operator. Everything
aforementioned upper I know from PHP.

Best regards, Alexander.

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

Re: [js] Equality bug?

Viktor Hesselbom-2
No, haXe doesn't have === but I thought == worked like strict equality. JavaScript has === though ;)

2011/9/12 Alexander Konotop <[hidden email]>
В Mon, 12 Sep 2011 15:36:43 +0200
Viktor Hesselbom <[hidden email]> пишет:

> Hello!
>
> Not sure if this is considered a bug or correct behavior.
> When targeting JavaScript and comparing an int and a string with the
> "same value" haXe outputs it as a match.
>
> Look at this example:
>
> *var a = [4, "4"];*
> *trace (a[0] == a[1]); // true*
> *trace (untyped __js__("a[0] == a[1]")); // true*
> *trace (untyped __js__("a[0] === a[1]")); // false*
>
> What do you think?
>
> Best,
> Viktor

==  => same value
=== => same value and same type
4   => int
"4" => string

P.S. I didn't know that HaXe has "===" operator. Everything
aforementioned upper I know from PHP.

Best regards, Alexander.

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


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

Re: [js] Equality bug?

Viktor Hesselbom-2
Ok, stupid me not looking up facts before posting. It's supposed to be loose equality to be the same across multiple platforms.

Nvm. ;)

2011/9/12 Viktor Hesselbom <[hidden email]>
No, haXe doesn't have === but I thought == worked like strict equality. JavaScript has === though ;)


2011/9/12 Alexander Konotop <[hidden email]>
В Mon, 12 Sep 2011 15:36:43 +0200
Viktor Hesselbom <[hidden email]> пишет:

> Hello!
>
> Not sure if this is considered a bug or correct behavior.
> When targeting JavaScript and comparing an int and a string with the
> "same value" haXe outputs it as a match.
>
> Look at this example:
>
> *var a = [4, "4"];*
> *trace (a[0] == a[1]); // true*
> *trace (untyped __js__("a[0] == a[1]")); // true*
> *trace (untyped __js__("a[0] === a[1]")); // false*
>
> What do you think?
>
> Best,
> Viktor

==  => same value
=== => same value and same type
4   => int
"4" => string

P.S. I didn't know that HaXe has "===" operator. Everything
aforementioned upper I know from PHP.

Best regards, Alexander.

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



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

Re: [js] Equality bug?

Nicolas Cannasse
In reply to this post by Viktor Hesselbom-2
Le 12/09/2011 15:36, Viktor Hesselbom a écrit :

> Hello!
>
> Not sure if this is considered a bug or correct behavior.
> When targeting JavaScript and comparing an int and a string with the
> "same value" haXe outputs it as a match.
>
> Look at this example:
>
> /var a = [4, "4"];/
> /trace (a[0] == a[1]); // true/

Here your Array is Dynamic and equality between two Dynamic values is
platform specific (as many things occuring when using Dynamic).

Best,
Nicolas

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

Re: [js] Equality bug?

Viktor Hesselbom-2
Ah, I see. Makes sense.

2011/9/13 Nicolas Cannasse <[hidden email]>
Le 12/09/2011 15:36, Viktor Hesselbom a écrit :
Hello!

Not sure if this is considered a bug or correct behavior.
When targeting JavaScript and comparing an int and a string with the
"same value" haXe outputs it as a match.

Look at this example:

/var a = [4, "4"];/
/trace (a[0] == a[1]); // true/

Here your Array is Dynamic and equality between two Dynamic values is platform specific (as many things occuring when using Dynamic).

Best,
Nicolas

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


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

Re: [js] Equality bug?

Yanis Benson
In reply to this post by Nicolas Cannasse

Why don't we enforce strict equality for dynamics just for JS?

On 13 Sep 2011 20:20, "Nicolas Cannasse" <[hidden email]> wrote:
> Le 12/09/2011 15:36, Viktor Hesselbom a écrit :
>> Hello!
>>
>> Not sure if this is considered a bug or correct behavior.
>> When targeting JavaScript and comparing an int and a string with the
>> "same value" haXe outputs it as a match.
>>
>> Look at this example:
>>
>> /var a = [4, "4"];/
>> /trace (a[0] == a[1]); // true/
>
> Here your Array is Dynamic and equality between two Dynamic values is
> platform specific (as many things occuring when using Dynamic).
>
> Best,
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org

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

Re: [js] Equality bug?

Cauê W.
maybe we should enforce strict equality on every target? I know php and avm2 accept them. And neko and cpp kinda does it already.

2011/9/13 Yanis Benson <[hidden email]>

Why don't we enforce strict equality for dynamics just for JS?

On 13 Sep 2011 20:20, "Nicolas Cannasse" <[hidden email]> wrote:
> Le 12/09/2011 15:36, Viktor Hesselbom a écrit :
>> Hello!
>>
>> Not sure if this is considered a bug or correct behavior.
>> When targeting JavaScript and comparing an int and a string with the
>> "same value" haXe outputs it as a match.
>>
>> Look at this example:
>>
>> /var a = [4, "4"];/
>> /trace (a[0] == a[1]); // true/
>
> Here your Array is Dynamic and equality between two Dynamic values is
> platform specific (as many things occuring when using Dynamic).
>
> Best,
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org

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


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

Re: [js] Equality bug?

Franco Ponticelli
In a js is not a good idea because undefined !== null and I feat that is used in some places ... I may be wrong.

Franco

On Tue, Sep 13, 2011 at 5:49 PM, Cauê Waneck <[hidden email]> wrote:
maybe we should enforce strict equality on every target? I know php and avm2 accept them. And neko and cpp kinda does it already.

2011/9/13 Yanis Benson <[hidden email]>

Why don't we enforce strict equality for dynamics just for JS?

On 13 Sep 2011 20:20, "Nicolas Cannasse" <[hidden email]> wrote:
> Le 12/09/2011 15:36, Viktor Hesselbom a écrit :
>> Hello!
>>
>> Not sure if this is considered a bug or correct behavior.
>> When targeting JavaScript and comparing an int and a string with the
>> "same value" haXe outputs it as a match.
>>
>> Look at this example:
>>
>> /var a = [4, "4"];/
>> /trace (a[0] == a[1]); // true/
>
> Here your Array is Dynamic and equality between two Dynamic values is
> platform specific (as many things occuring when using Dynamic).
>
> Best,
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org

--

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


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


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

Re: [js] Equality bug?

Nicolas Cannasse
Le 13/09/2011 19:10, Franco Ponticelli a écrit :
> In a js is not a good idea because undefined !== null and I feat that is
> used in some places ... I may be wrong.

Yes that's exactly the reason.
For instance accessing an array outside of its bounds or an
uninitialized object field will return undefined instead of null.

Nicolas

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

Re: [js] Equality bug?

Cauê W.
ohh!

makes sense! ; )

2011/9/13 Nicolas Cannasse <[hidden email]>
Le 13/09/2011 19:10, Franco Ponticelli a écrit :

In a js is not a good idea because undefined !== null and I feat that is
used in some places ... I may be wrong.

Yes that's exactly the reason.
For instance accessing an array outside of its bounds or an uninitialized object field will return undefined instead of null.


Nicolas

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


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