Type Compatibility
A type T is compatible with another type S if the following conditions are met:
- Type S is not polymorphic
- The prototype of type T is compatible with instances of type S
Or:
- Type S is polymorphic
- Type T and S are both based on the same type
- Type S does not extend the base type with new instance members
- Type S instance members have exactly the same type as the base type
This relationship is noted:
Note: There is an implicit conversion from any type compatible with S to type S.
Example:
def Mansion = new House
{
def ^windowCount = 30 # override instance member default value
}
def CountryHouse = new House
{
Area groundsArea
Tree[] trees
}
CountryHouse is compatible with Mansion
Rationale: The compatibility rule allows operations of S to be used on variables of a compatible type. This is an important rule for polymorphism. Non-polymorphic type variables
can still be used where a compatible type instance is expected if their structure is compatible.
For polymorphic types, the S
type can not expand the base type with instance members or conflicts
would be possible.
^ 4.6.2. Instance Methods
v 4.8. Use of Variables as Type