swift - 类型别名 "Bar"不是类型 "Foo"的成员

标签 swift compiler-errors

我有以下设置:

// 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 block 和 baz() 的调用站点,那么一切正常。

也就是说,编译运行没有问题:

public class Foo {
    public typealias Bar = [String : Int]
}


func take(fooBar: Foo.Bar) {
    print(fooBar)
}


public typealias FooBar = Foo.Bar


take(fooBar: [:])

所以我的问题是:这是怎么回事,我该如何解决?

最佳答案

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

关于swift - 类型别名 "Bar"不是类型 "Foo"的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46816925/

相关文章:

ios - popToViewController 首先执行

ios - Swift 5 - 中间 View Controller 短暂出现 - 应该删除吗?

class - 检查init方法的参数

java - 如何修复 “Error: Can not find or load the main class”?

c# - 添加方法导致编译错误 C# ASP

java - 为什么Java泛型不能用于静态方法?

swift - 快速编译器的奇怪行为

ios - 检索子项的子值

android-studio - Android Studio无法打开项目

java - Calendar类型的set(int,int)方法不适用于参数(int,String)