Dodo doc > Types > Type Compatibility


Type Compatibility

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

Type T is also compatible with type S if type S is polymorphic and the following conditions are met:

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 # overrides default count
}

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. Constructors and Methods

v 4.8. Use of Variables as Type