Wintermute Engine > Bug reports

boolean evaluation inconsistency

(1/1)

jbw:

--- Code: ---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);
}

--- End code ---
Result:
  WME treats [1] as true
  WME treats [1] as true
  WME treats [1] as false

metamorphium:
I am not sure this is a right thing to do.

how about:


--- Code: ---var t = new String("1");

booltest(t);

--- End code ---

?

jbw:

--- Quote from: metamorphium on April 02, 2008, 03:40:53 PM ---I am not sure this is a right thing to do.

--- End quote ---

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.

Navigation

[0] Message Index

Go to full version