Loading ...
Sorry, an error occurred while loading the content.

Re: [eiffel_software] Trouble with my design and void-safe mode

Expand Messages
  • Alexander Kogtenkov
    Hi Jimmy, If you are using EiffelStudio 7.0, it provides a nice way to address the cases like this one. Originally it was developped for the situations when a
    Message 1 of 4 , Feb 18, 2012
    View Source
    • 0 Attachment
      Hi Jimmy,

      If you are using EiffelStudio 7.0, it provides a nice way to address the cases like this one.
      Originally it was developped for the situations when a target type cannot be created. This
      may happen, for example, when the project is on its early stages, the result type is deferred
      and there are no effective descendants yet. Still the standard requires the result to be
      initialized. In theory one can change the result type to be deferred, but this is not very
      attractive since it breaks the original design.

      Because of this requirement to be able to work with incomplete but still void-safe projects
      starting from version 7.0, EiffelStudio supports so called "design mode". In a few words,
      it does not report void-safe errors in some parts of the code are soon as it detects that these
      parts are unreachable.

      There are several patterns that are used by EiffelStudio to detect unreachable code. I'll
      mention the most relevant for your code:

      1. Use of a mandatory check instruction:
      check do_not_call: False then end -- Note the use of "then" keyword

      2. Call of a feature with false postcondition (e.g., {EXCEPTIONS}.die):
      ;(create {EXCEPTIONS}).die (1) -- Terminate the application

      In the case 1, an exception is raised and therefore your routine does not terminate normally.
      As a result, it never returns Void. In the case 2, the application is terminated, so the potential
      caller of the features does not get Void as well.

      So, your code may be changed to look like (comments and preconditions are omitted for brevity):

      node_anchor: VALUED_NODE [N]
      do
      check do_not_call: False then end
      end

      or

      node_anchor: VALUED_NODE [N]
      do
      (create {EXCEPTIONS}).die (1)
      end

      Best regards,
      Alexander Kogtenkov


      ----- Original Message -----
      From: "Jimmy Johnson" <boxer41a@...>
      To: <eiffel_software@yahoogroups.com>
      Sent: Saturday, February 18, 2012 3:31 AM
      Subject: [eiffel_software] Trouble with my design and void-safe mode


      >I have a library for graphs (nodes, edges, etc.) in which descendant features are covariantly redefined and anchored using a
      >feature to avoid adding an attribute. When switching to void safety, I am forced to create a result; but the type of the result
      >does not have a default_create feature. Here's the class:
      >
      > class
      > VALUED_EDGE [N]
      > inherit
      > EDGE
      > redefine
      > node_anchor
      > end
      > create
      > default_create,
      > connect
      > feature {NONE} -- Anchors (for covariant redefinitions)
      > node_anchor: VALUED_NODE [N]
      > -- Anchor for features using nodes.
      > -- Not to be called; just used to anchor types.
      > -- Declared as a feature to avoid adding an attribute.
      > require else
      > not_callable: False
      > do
      > check
      > do_not_call: False
      > -- Because give no info; simply used as anchor.
      > end
      > create Result -- <------ had to add this line, but doesn't work
      > end
      > end
      >
      > The creation feature for a VALUED_NODE [N] is:
      > make_with_value (a_value: like value_anchor)
      >
      > and, `value_anchor' is of type N. I do not provide a default_create feature because we should not create a valued_node with no
      > value.
      >
      > This pattern worked well for me until switching to void-safety. Any suggestions or ways to make this work? Thanks
      >
      > jjj
    Your message has been successfully submitted and would be delivered to recipients shortly.