I'm seeing some odd behavior with the AS3 compiler. I say it's "odd"
because it's at variance with the vast majority of C language
derivatives (in fact, I'll go out on a limb and say ALL of them). The
behavior I'm seeing is this:
If I have
package {
public class badscope {
public function dummy() : void {
if (new Date() != null) {
var foo : Number = 3;
} else {
var foo : Number = 4;
}
}
}
}
the cmopiler is telling me that "foo" is a duplicate declaration. Um.
Every other block structured language I'm familiar with scopes local
variable declaration to the enclosing block, so the foo's do not exist
in the same lexical scope and there is no conflict. To me, if this
behavior of placing all variable declarations in the top level
function's scope is in fact the desired behavior, it's a HUGE step
backwards.
Please help me to understand why I'm seeing the behavior I am, and why
it's not breaking lexical scoping rules common to C derivatives.