Compiler errors Eiffel:在或和中的本地声明未能编译

Compiler errors Eiffel:在或和中的本地声明未能编译,compiler-errors,eiffel,Compiler Errors,Eiffel,编译器正在抱怨未知标识符,似乎它无法识别我的多个声明中的任何一个,我错在哪里 if attached {INTEGER_REF} field.item as l_int or attached {INTEGER_64} field.item as l_int or ( attached {TUPLE} field.item as l_tuple and then attached {INTEGER_64} l_tuple.item (1) as l_int ) t

编译器正在抱怨未知标识符,似乎它无法识别我的多个声明中的任何一个,我错在哪里

if attached {INTEGER_REF} field.item as l_int
        or attached {INTEGER_64} field.item as l_int
        or ( attached {TUPLE} field.item as l_tuple and then attached {INTEGER_64} l_tuple.item (1) as l_int ) then
    Result.put_integer (l_int.to_integer_64, primary_key_db_column_name)
elseif attached {STRING} field.item as l_s then
    Result.put_string (l_s, primary_key_db_column_name)
end

更新 由于这似乎是一个有效的表达式,我认为如果在我的的每个分支中都声明了
l_int
,那么我应该能够在范围中使用它

但是这个表达式似乎是有效的

if attached a.b as l_b and then attached l_b.c as l_c then
    l_c.is_available_in_this_scope
    l_b.is_available_in_this_scope
else
    io.putstring ("you are wrong dear and either l_b and l_c are not available!")
end
而这个不是

if attached a.b as l_b and then attached l_b.c as l_c
        or attached a.x as l_b and then attached l_x.d as l_c then
    l_c.is_available_in_this_scope -- Compiler complain about l_c
    l_b.is_available_in_this_scope -- Compiler complain about l_b
else
    io.putstring ("you are wrong dear and either l_b and l_c are not available!")
end
用我的代码 此编译

    if attached {INTEGER_REF} field.item as l_int then
        Result.put_integer (l_int.to_integer_64, primary_key_db_column_name)
    elseif attached {INTEGER_64} field.item as l_int then
        Result.put_integer (l_int, primary_key_db_column_name)
    elseif attached {TUPLE} field.item as l_tuple and then attached {INTEGER_64} l_tuple.item (1) as l_int then
        Result.put_integer (l_int, primary_key_db_column_name)
    elseif attached {STRING} field.item as l_s then
        Result.put_string (l_s, primary_key_db_column_name)
    else
        logger.write_error ("to_json-> Type not found in matching:" + field.item.out)
        check
            not_found_item_type: False
        end
    end
而这个不是

if attached {INTEGER_REF} field.item as l_int then
    Result.put_integer (l_int.to_integer_64, primary_key_db_column_name)
elseif attached {INTEGER_64} field.item as l_int
        or attached {TUPLE} field.item as l_tuple and then attached {INTEGER_64} l_tuple.item (1) as l_int then
    Result.put_integer (l_int, primary_key_db_column_name) -- Unknown identifier `l_int`
elseif attached {STRING} field.item as l_s then
    Result.put_string (l_s, primary_key_db_column_name)
else
    logger.write_error ("to_json-> Type not found in matching:" + field.item.out)
    check
        not_found_item_type: False
    end
end

首先,对于同一范围内的多个对象测试局部变量,不能使用相同的标识符(l_int)。

对象测试有作用域。用
OT
表示对象测试,其范围为

if OT         then A else B end
if OT and ... then A else B end
if OT or  ... then C else B end
只是
A
。因此,对于析取,作用域为空,并且不能在任何分支中使用相应的对象测试局部

如果条件测试中有两个对象测试,则它们的范围可能重叠或不重叠:

if OT1 and      OT2 then A else B end
if OT1 and then OT2 then A else B end
if OT1 or       OT2 then C else B end
这里,与前面一样,
OT1
的对象测试局部变量具有范围
a
。此外,对于
,范围包括
OT2
,尤其是
OT2
可以使用
OT1
的本地。出于同样的原因,
OT2
不能使用
OT1
的同一对象本地测试

对于析取,对象测试局部变量
OT1
OT2
的作用域都是空的。为了提供更多信息,具有助记名称的相同代码如下所示:

if attached e1 as x and      attached e2_without_x as y then use_x_and_y else B end
if attached e1 as x and then attached e2_with_x    as y then use_x_and_y else B end
if attached e1 as x or       attached e2_without_x as y then no_x_no_y   else B end
如果所有涉及的表达式的类型都相同,则仍然可以用一个第一分支重写示例(事实并非如此,因为存在类型
INTEGER\u 64
INTEGER\u REF
):


但是这变得太麻烦了,使用多个分支或临时局部变量看起来是更好的选择。

Thx,但这就是我没有做的吗?你的建议对我有何影响?请参阅我对亚历山大的编辑和问题,以获得更精确的答案,谢谢!很多thx,这对我很有帮助,但我对我的问题做了编辑,因为在这种情况下我仍然有疑问。。。编译器在这里抱怨是因为
l_int
可以是整数REF和整数64吗?@Pipo这是因为对于析取,对象测试局部变量的作用域是空的。并且,每个对象测试都是单独考虑的,即两个对象测试局部不能视为一个。因此,对于析取,您有两个空作用域,并且不能使用任何一个变量。对不起,即使阅读您大约10次,我仍然没有抓住要点:-(你看到我的编辑了吗?如果你有动机,也许你可以给你的答案添加一个编辑!@Pipo没有规则将两个对象测试中的对象测试局部变量组合成一个变量。此外,如果对象测试用于析取,则对象测试局部变量的作用域为空。我用更多的测试更新了答案。)这次得到了!!!由于
和INTEGER\u 64/INTEGER\u REF使它不可用,这不是因为编译限制,而是我的错误Maaaany thx!!
if attached
       if attached {INTEGER_64_REF} field.item as i then
           i
       elseif
           attached {TUPLE} field.item as t and then
           t.count > 0 and then
           attached {INTEGER_64_REF} t.item (1) as i
       then
           i
       else
           Void
       end
   as j
then
   -- Use j
...