Wintermute Engine Forum

Wintermute Engine => Bug reports => Topic started by: jbw on April 02, 2008, 11:20:37 AM

Title: boolean evaluation inconsistency
Post by: jbw on April 02, 2008, 11:20:37 AM
Code: [Select]
booltest(1);
booltest("1");
booltest(new String("1"));

function booltest(b)
{
  var q; if (b) q = "true"; else q = "false";
  Game.LOG("WME treats [" + b + "] as " + q);
}
Result:
  WME treats [1] as true
  WME treats [1] as true
  WME treats [1] as false
Title: Re: boolean evaluation inconsistency
Post by: metamorphium on April 02, 2008, 03:40:53 PM
I am not sure this is a right thing to do.

how about:

Code: [Select]
var t = new String("1");

booltest(t);

?
Title: Re: boolean evaluation inconsistency
Post by: jbw on April 02, 2008, 10:44:07 PM
I am not sure this is a right thing to do.

I am pretty sure it is. As you can see, my test routine displays what it get as argument and it is "1". This code is not just from my head, but from the working example.
I've done a bunch of tests to catch the truth about booleans. It doesn't matter if you pass variable referencing string object or immediately created object in the call itself, result is always the same.

I have experience of creating compilers, so I know this is the hell of implicit conversions. It's hard to track in mind all weird possibilities. In this case perhaps no string should match "true" (the easiest way), but if the one ordinary string of digits does, obviously the corresponding string object should match it as well.