Ограничение реализации: функция класса only_from_type использует встроенный агент - PullRequest
0 голосов
/ 21 января 2020

Есть ли семанти c за неспособностью иметь агента в подпрограмме ensure class или это текущее ограничение компилятора?

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

выдает следующую ошибку

И я думаю, что здесь есть опечатка, не должно ли быть Implementation constraint вместо 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

1 Ответ

2 голосов
/ 21 января 2020

Встроенный агент (как обычная функция) принимает неявный аргумент - текущий объект. В объекте класса (где он используется в примере) нет текущего объекта. Следовательно, встроенный агент не может быть вызван из функции класса.

С другой стороны, может быть возможно проверить, что агент не использует Current, и, следовательно, безопасно использовать в особенность класса. Компилятор, сообщающий об ошибке, не реализует такую ​​функциональность и вместо этого сообщает об ошибке ограничения реализации.

...