Eiffel 埃菲尔铁塔中的可拆卸通用到通用
我有一个具有post条件的功能,如下所示:Eiffel 埃菲尔铁塔中的可拆卸通用到通用,eiffel,Eiffel,我有一个具有post条件的功能,如下所示: checkValue (k: K): detachable V do ... end ensure some_post_condition: checkKey (Result) 下面是“checkKey”的原型: 由于“Result”是“detaccable V”类型,我尝试将其作为参数传递给“checkKey”,它只接受“V”类型而不接受“detaccable V”,因此它无法编译 下面是编译错误所说的: Argument name: v
checkValue (k: K): detachable V
do
...
end
ensure
some_post_condition:
checkKey (Result)
下面是“checkKey”的原型:
由于“Result”是“detaccable V”类型,我尝试将其作为参数传递给“checkKey”,它只接受“V”类型而不接受“detaccable V”,因此它无法编译
下面是编译错误所说的:
Argument name: v
Argument position: 1
Formal argument type: Generic #1
Actual argument type: detachable Generic #1
如何将可拆卸的通用型转换为通用型?有几个选项:
checkValue
的类型从detaccable V
更改为V
checkKey
的参数类型从V
更改为可分离的V
- 如果
应始终附加结果
result_attached: attached Result some_post_condition: checkKey (Result)
- 如果
可能是可拆卸的(在这种情况下,它被认为是有效的):结果
result_attached: attached Result
some_post_condition: checkKey (Result)
some_post_condition: attached Result implies checkKey (Result)