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) –