What is assignment compatibility?

Pascal is a strongly-typed language which means, amoung other things, that every value used in a Pascal program has a type, and each value's type controls where and how it can be used. One way Pascal controls where and how values can be used is through the concept of assignment compatibility. Assignment compatibility is a relationship between values and types, and for any given value and type the relationship either exists between them or it does not (i.e. the value is either assignment compatible with the type or it is not).

Irie Pascal implements the assignment compatibility rules defined by Standard Pascal (ISO/IEC 7185), and adds one more rule to support variable length string types. The first five rules below are taken from ISO/IEC 7185 and the sixth one was added to support variable length string types.

A value (V) of type T2 shall be designated assignment compatible with a type T1 if any of the following six statements is true:

  1. T1 and T2 are the same type, and that type is not a file type for a type that contains a file type.
  2. T1 is the real type and T2 is an integral type.
  3. T1 and T2 are compatible ordinal types, and V is in the closed interval specified by the type T1.
  4. T1 and T2 are compatible set types, and all the members of V are in the closed interval specified by the base-type of T1.
  5. T1 and T2 are fixed length string types with the same length.
  6. T1 is a variable length string type and either T2 is a variable length string type, or T2 is a fixed length string type, or T2 is the char type. In addition the length of V must not be greater then the maximum length of T1.
Assignment compatibility is used to control where and how values can be used, in the following situations: