【发布时间】:2017-10-18 18:30:57
【问题描述】:
我有以下设置:
// 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,它声称“类型别名 'FooBar' 引用自身” -
如果你在 typealias 和扩展名之间插入
let fb = FooBar()然后它会再次编译——这让我怀疑是编译器错误。 -
归档SR-6179
标签: swift compiler-errors