There are three situations in which the compiler ignores type mismatch errors in strict mode, deferring possible type errors until runtime:
When an untyped expression is assigned to a typed variable or parameter, or returned from a function with a declared return type
When any expression is assigned to a typed variable or parameter whose declared type is Boolean, or returned from a function whose declared return type is Boolean
When any numeric value is used where an instance of a different numeric type is expected
Let's look at each of the preceding cases with an example.
First, we'll create an untyped variable,
pet, and assign the value of that variable
to a typed variable,
var pet:* = new VirtualPet("Francis"); pet = new Date(); var d:Date = pet;
pet can contain any
type of value, on line 3, the compiler cannot determine whether
pet's value belongs to the datatype
Date. To determine whether the
pet belongs to the
datatype Date, the code must be
executed, not just compiled. Once the code is actually executing,
ActionScript can then determine the result of the assignment attempt.
In the case of the preceding code, the value in
pet (assigned on line 2) does indeed belong
to the datatype Date (even though
pet's value on line 1 was
originally incompatible with Date). Hence, the assignment proceeds
without causing an error.
Next, consider the following code which defines a variable,
b, of type Boolean, and assigns
b an integer value, 5: ...