Search code examples
eiffelvoid-safety

Eiffel: Error: variable is not properly set. in make calling default_create or any parent calling/redefining default_create


Not sure exactly, but it makes various time I got a Error: variable is not properly set. in creation procedures' calling order. I figured out that creating class attributes before calling default_create seemed to solve the problem. Why is that so? It doesn't seem that default_create calls something in my make routine??!!!

Try to make an example even if I don't think I can reproduce it with a simple example...

Working

class A

feature

    attr: B

    make
        do
            create attr
            default_create
        end

end

Error: variable is not properly set.

class A

feature

    attr: B

    make
        do
            default_create
            create attr
        end

end

Solution

  • default_create makes some calls. There may be a call on Current (direct or indirect, e.g. if Current is passed somewhere as an argument). If the attribute attr is not set at this point, the current object is not completely initialized and using it in regular feature calls may lead to calls on Void target (due to polymorphism, in particular). In order to avoid this issue, it is required to set all attributes before any calls involving Current.