Thanks.
It is not due to using separate files or having
multiple subclasses.
The issue is that initializers are added to an
inherited __Init method if one exists, instead of defining a new one. This is of course unintended and will be fixed.
In other words,
Code: Select all
MsgBox bs().subProp ; 3
class bs {
baseProp1 := 1 ; HasMethod(bs.Prototype, "__Init") = false, so __Init is defined
baseProp2 := 2 ; this line is added to GetMethod(bs.Prototype, "__Init")
}
class sub extends bs {
subProp := 3 ; this line is added to GetMethod(sub.Prototype, "__Init")
}
When you combined A and B into one file, you changed the order that the classes are defined in, putting them before the base class. This is hard to see in your post, because of the order you write the files and the multiple #Include directives.
You can replicate what the parser
should be doing like this:
Code: Select all
MsgBox bs().subProp ; error
class bs {
baseProp1 := 1, baseProp2 := 2
}
class sub extends bs {
__Init() {
super.__Init()
;<instance var initializers are inserted here>
}
subProp := 3 ; sub has __Init (inherited), so this line is added to it
}
But according to the current documentation, "a single class definition must not contain both an __Init method and an instance variable declaration". What's left unsaid is "(because otherwise, you'll either get a duplicate declaration error or the initializers will be dumbly inserted at the end of the function, which may cause confusion and not necessarily allow the initializers to be evaluated; this should not be relied upon as it may change)".
If you define __Init explicitly and put the initializer into it yourself, you are compliant with the current documentation.