Shouldn't the following code throw an error instead of executing?
class Weird
{
public static function main()
{
var weirdPerson = Type.createInstance(Person,[["What", "the", "?"]]);
trace(weirdPerson.likesCake);
// Outputs [What,the,?]
var normalPerson = Type.createInstance(Person,[true]);
trace(normalPerson.likesCake);
// Outputs John Doe
}
}
class Person
{
public var likesCake:Bool;
public function new(?likesCake:Bool=true)
{
this.likesCake = likesCake;
}
}
The wrong type is being parsed to the constructor of the weirdPerson but its still being accepted. The Bool property 'likesCake' of the weirdPerson is actually assigned a String array!? Is there something wrong here or is this the expected functionality? Maybe the type of the likesCake property has changed at runtime from Bool to Array only for this instance of the Person class?