Search code examples
typespolymorphismeiffel

Eiffel: Do expanded types conform to ANY?


  1. Assume that foo: ANY is an assignable entity.
  2. What happens when I do foo := create {BOOLEAN}?

It would fail always, because BOOLEAN (an expanded type) does not conform to ANY (a reference type), correct?


Solution

  • Expanded types conform to reference ones (provided that other conformance requirements are satisfied). So, the example you mention works just fine. Moreover, it is ok to write foo := True.

    The key difference after such reattachments is that copy semantics of expanded types is preserved, i.e. if there is an entity bar of type ANY, the assignment bar := foo will attach a copy of the boolean object to bar, not the same reference. So, if a value of the object attached to foo is changed afterwards, bar remains unchanged.

    Answering your original question, BOOLEAN conforms to ANY.