Dodo doc > Types > Type Compatibility
A type T is compatible with another type S if the following condition is met:
- The prototype of type T is compatible with instances of type S
Type T is also compatible with type S if type S is polymorphic and the following conditions are met:
- 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.
def Mansion = new House
def ^windowCount = 30 # overrides default count
def CountryHouse = new House
# 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