0

As far as I understand,

  • separate does not conform to non separate
  • non separate conforms to separate

so, that's the reason the compiler complains when I say like Current, when the P and S I specified into the RELATIONSHIP class are non separate

Is there a way to anchor the relationship: RELATIONSHIP[unseparate like Current, RABBIT] or do I have to specify it with relationship: RELATIONSHIP[PERSON, RABBIT]?

If no any reason for that escaping my understanding?

see the example above

RELATIONSHIP

class
    RELATIONSHIP[P -> ANIMAL create default_create, make_from_separate end, S -> ANIMAL create default_create, make_from_separate end]

create
    make,
    make_from_separate

feature {NONE} -- Initialize

    make (v: like primary)
        do
            primary := v
            create secondary
        end

    make_from_separate (other: separate like Current)
        do
            create primary.make_from_separate (other.primary)
            create secondary.make_from_separate (other.secondary)
        end

feature -- Access

    primary: P
    secondary: S

end

PERSON

class PERSON

inherit
    ANIMAL
        redefine
            default_create
        end

create
    default_create,
    make_from_separate

feature -- Init

    default_create
        do
            create relationship.make (Current)
        end

    make_from_separate (other: separate like Current)
        do
            create relationship.make_from_separate (other.relationship)
        end

feature -- access

    -- relationship: RELATIONSHIP[like Current, RABBIT] -- not compiling
    relationship: RELATIONSHIP[PERSON, RABBIT] -- compiling

end
Pipo
  • 4,653
  • 38
  • 47
  • 1
    It's possible that language rules might need to be reviewed to treat **like Current** as non-separate in scenarios like you describe. – Alexander Kogtenkov Jun 05 '20 at 09:08
  • Nice, actually on my case, it prevents me to have polymorphism on certain classes, I have to differ creation of the relationship and then redefine it into child class :( you'll say like most of the languages not having anchored types... a nice language makes us demanding – Pipo Jun 05 '20 at 12:41

0 Answers0