【问题标题】:Type alias "Bar" is not a member of type "Foo"类型别名“Bar”不是“Foo”类型的成员
【发布时间】: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


【解决方案1】:

这是 Swift 编译器中的一个错误。你可以在这里追踪它:SR-6179

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    相关资源
    最近更新 更多