2
我有以下设置:类型别名“酒吧”不是类型的成员“富”
// MARK: Basis
public class Foo {
public typealias Bar = [String : Int]
}
func take(fooBar: Foo.Bar) {
print(fooBar)
}
// MARK: Problems
public typealias FooBar = Foo.Bar
public extension Dictionary
where Key == FooBar.Key,
Value == FooBar.Value {
func baz() {
take(fooBar: self as! FooBar)
}
}
// MARK: Usages
FooBar().baz()
take(fooBar: [:])
这似乎没什么问题,但我得到这个错误:
main.swift:16:31: error: type alias 'Bar' is not a member type of 'Foo'
public typealias FooBar = Foo.Bar
~~~^
我非常困惑......它就在那里;我应该可以看到它。
这是最容易混淆的部分:如果我注释掉extension Dictionary
块和baz()
的调用站点,那么一切正常。
也就是说,这编译和运行没有问题:
public class Foo {
public typealias Bar = [String : Int]
}
func take(fooBar: Foo.Bar) {
print(fooBar)
}
public typealias FooBar = Foo.Bar
take(fooBar: [:])
所以我的问题:这是怎么回事?我该如何解决呢?
注意:如果我声明'FooBar = [String:Int]'和'Bar = FooBar',它声明“Type别名'FooBar'引用自身” –
如果您插入'let fb = FooBar()'在typealias和扩展之间,然后再编译 - 这让我怀疑是一个编译器错误。 –
提交[SR-6179](https://bugs.swift.org/browse/SR-6179) –