Dodo doc > Types > Type Compatibility


Type Compatibility

A type T is compatible with another type S if the following conditions are met:

Or:

This relationship is noted:

T ~ S

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