【发布时间】:2017-10-23 16:02:16
【问题描述】:
我有以下测试用例:
test_different_cursor: BOOLEAN
local
cursor: SET_ITERATION_CURSOR[INTEGER, INTEGER]
sets: ARRAY[SET[INTEGER, INTEGER]]
do
create sets.make_empty
check attached {SET_ITERATION_CURSOR[INTEGER, INTEGER]} d.different_cursor as current_cursor then
cursor := current_cursor
end
from
until
cursor.after
loop
sets.force (cursor.item, sets.count + 1)
cursor.forth
end
end
在这里,在 from~end 的循环中,我尝试调用 Array 类的强制功能,但编译器一直提示该行出现以下错误:
Error code: VUAR(2)
Type error: non-compatible actual argument in feature call.
What to do: make sure that type of actual argument is compatible with
the type of corresponding formal argument.
Class: MY_TESTS
Feature: test_different_cursor
Called feature: force (v: [like item] G; i: INTEGER_32) from ARRAY
Argument name: v
Argument position: 1
Formal argument type: SET [INTEGER_32, INTEGER_32]
Actual argument type: TUPLE [INTEGER_32, INTEGER_32]
Line: 193
loop
-> sets.force (cursor.item, sets.count + 1)
cursor.forth
在这种情况下,似乎我需要创建继承 ARRAY 类的 SET 类并在那里重新定义强制功能。但我不确定这是修复编译错误的正确方法。这是我的 SET 类的样子:
class
SET[A, B]
create
make
feature
valueA: A
valueB: B
feature
make (first: A; second: B)
do
valueA := first
valueB := second
end
end
我必须做什么才能解决这个问题?
【问题讨论】:
-
如果您提供
VUAR(2)中报告的更详细信息(例如实际参数的类型)会有所帮助。从当前代码很难推断出cursor.item返回的内容。或者,您可以提供SET_ITERATION_CURSOR类的缩写形式。 -
@AlexanderKogtenkov 错误代码:VUAR(2) 类型错误:功能调用中的实际参数不兼容。怎么做:确保实际参数的类型与相应的形式参数的类型兼容。类:MY_TESTS 特征:test_different_cursor
-
类型呢?
-
@AlexanderKogtenkov 抱歉,没有注意到还有更多,因此我只是在上面添加了更多错误。
标签: inheritance iterable eiffel