6

这显然是不可能的...

role Versioned {
    method version () {
        return self.^api;
    }
}

class WithApi:ver<0.0.1>:auth<github:JJ>:api<0> does Versioned {}
class WithApi:ver<0.0.1>:auth<github:JJ>:api<1> does Versioned {}

say WithApi:api<0>.new.version;
say WithApi:api<1>.new.version;

这与

==SORRY!=== Error while compiling /home/jmerelo/progs/perl6/my-perl6-examples/api-versioned.p6
Redeclaration of symbol 'WithApi'
at /home/jmerelo/progs/perl6/my-perl6-examples/api-versioned.p6:11
------> 1>:auth<github:JJ>:api<1> does Versioned⏏ {}

那么甚至可以在一个程序中use使用不同的s,相同的名称吗?api

更新:如果它们包含在不同的文件中,这是获得的错误:

P6M Merging GLOBAL symbols failed: duplicate definition of symbol WrongType
4

1 回答 1

7

在此示例中,有两件事造成了问题:

  • class默认情况下our,这会导致名称冲突
  • 类的短名称在外部命名空间中相同,导致冲突

如果我们稍微修改一下代码:

role Versioned {
    method version () {
        return self.^api;
    }
}

my constant one = my class WithApi:ver<0.0.1>:auth<github:JJ>:api<1> does Versioned {}
my constant two = my class WithApi:ver<0.0.1>:auth<github:JJ>:api<2> does Versioned {}

say one.version;  # 1
say two.version;  # 2

我确实发现:api<0>. 显然这被认为相当于没有 :api设置,导致一个空字符串而不是0.

于 2020-04-05T09:08:29.980 回答