[mtasc] Boolean expressions and ECMA-262
Steve Webster
steve.webster at featurecreep.com
Thu Apr 14 23:41:39 CEST 2005
Hi Robert,
> 11.11
> NOTE The value produced by a && or || operator is not necessarily of type
> Boolean. The value produced will always be the value of one of the two
> operand expressions.
Interesting. So I guess that for an assignment MTASC should check that
all operands for a boolean expression return a datatype that validly can
be stored in the target...
// Some vars
var a:String = "Hello";
var b:Object = new Object();
var c:Number = 0;
// Correct - both String and Object can be stored in Test1
var test1:Object = a || b; // Would be String(hello)
// Incorrect - cannot sture Object in String without cast.
// Should the compiler throw an error here?
var test2:String = a || b;
// What happens here?
var test3:Object = a && b;
// And here?
var test4:Object = a && c;
I'm slightly confused over the values of 'test3' and 'test4'. For
'test3' both of the operands in the expression will convert to
Boolean(true), but which one (if either) gets assigned to 'test3'? What
about 'test4'? Since 'c' will convert to Boolean(false) making the
expression fail, does the value of 'test4' become Boolean(false) or 'null'?
I'm not necessarily expecting conclusive answers here. I still believe
that boolean expressions should return Boolean results - that would
certainly clear up the uncertanties presented above - but I guess we're
stuck with what we have.
Steve
--
Steve Webster
Interactive Developer
Featurecreep Ltd
www.featurecreep.com
T: +44 (0)117 905 5047
More information about the mtasc
mailing list