Search code examples
eiffel

Implementation contraint: The class feature only_from_type uses an inline agent


Is there a semantic behind not being able to have an agent into a ensure class routine or is it a current compiler restriction?

only_from_type (some_items: CHAIN[like Current]; a_type: detachable like {ENUMERATE}.measuring_point_type_generation): LINKED_LIST[like Current]
        -- extends Result with given some_items which are equal to given type
    do
        create Result.make
        across
            some_items is l_item
        loop
            check
                attached_type: attached l_item.type as l_type
            then
                if attached a_type as l_a_type and then l_type.is_equal (l_a_type) then
                    Result.extend (l_item)
                end
            end
        end
    ensure
        some_items.for_all (
            agent (an_item: like Current; a_type_2: detachable like {ENUMERATE}.measuring_point_type_generation) do
                if attached a_type_2 as l_type_2_a and then
                    attached an_item.type as l_item_type and then
                    l_item_type.is_equal (l_type_2_a)
                then
                    Result := True
                end
            end (a_type)
            )
        instance_free: Class
    end

gives following error

And I think there is a typo here, shouldn't it be Implementation constraint instead of contraint?

Error code: VUCR

Implementation contraint: The class feature only_from_type uses an inline agent.
What to do: Remove the inline agent from the code or make the feature a non-class one.
Class: MEASURING_POINT
Feature: only_from_type
Line: 183
        some_items.for_all (
->        agent (an_item: like Current; a_type_2: detachable like {ENUMERATE}.measuring_point_type_generation) do
            if attached a_type_2 as l_type_2_a and then

Solution

  • An inline agent (like a regular feature) takes an implicit argument - current object. In a class feature (where it is used in the example), there is no current object. Therefore, an inline agent cannot be called from a class feature.

    On the other hand, it might be possible to check that the agent does not use Current, and, therefore, is safe to use in the class feature. The compiler reporting the error does not implement such a functionality, and reports an implementation constraint error instead.