Revival of manifest arrays

by Alexander Kogtenkov (modified: 2017 Sep 18)

The type system of Eiffel had a long-standing island where a type of an expression could rely on something outside of that expression. This island was a manifest array. When the manifest array was used as a source of a reattachment, its type depended on the target of the reattachment. So, exactly the same manifest array expression could lead to creation of objects of different types. Here is an example: comparable_array: ARRAY [COMPARABLE] numeric_array: ARRAY [NUMERIC] ... comparable_array := <<1, 2, 3>> numeric_array := <<1, 2, 3>> io.put_boolean (attached {ARRAY [COMPARABLE]} numeric_array) io.put_boolean (attached {ARRAY [NUMERIC]} comparable_array) The type of the first manifest array was ARRAY [COMPARABLE] and the type of the second one was ARRAY [NUMERIC]. The program printed FalseFalse.

This quirk – the dependency of a source expression on the target type of a reattachment – is now gone from the language. The type of a manifest array is always the same regardless of the surrounding context. It is either computed automatically or can be specified explicitly in the code. In the example above, the computed type is ARRAY [INTEGER] in both cases, so now the program prints TrueTrue.

If, however, the programmer wants ARRAY [COMPARABLE] attached to comparable_array, the explicit type specification can be used: comparable_array := {ARRAY [COMPARABLE]} <<1, 2, 3>>

If your code with a manifest array relies on the target type of a reattachment and does not compile with the new rules, EiffelStudio reports a warning and suggests an automatic fix when possible.

The new language rules are supported in EiffelStudio 17.11. More details about the mechanism can be found here.