【问题标题】:Why can't you use @autoclosure on a typealias to a function closure type?为什么不能在函数闭包类型的类型别名上使用 @autoclosure?
【发布时间】:2016-10-25 15:46:46
【问题描述】:

对这个有点惊讶。在 Swift 3 中,这段代码编译...

class func test(foo:@autoclosure () -> Void)
{
}

但这不是...

typealias VoidHandler = () -> Void

class func test(foo:@autoclosure VoidHandler)
{
}

你得到...

error: @autoclosure attribute only applies to function types

为什么不呢?好像是同一个东西的别名吧?

【问题讨论】:

  • 你是对的 Marquel,这已被报告为 Swift 3 中的一个错误:bugs.swift.org/browse/SR-2688。现在,您必须通过使用实际的闭包类型(例如 () -> String)而不是使用别名来声明 @autoclosure 来解决它。

标签: swift swift3 type-alias


【解决方案1】:

看起来这是(曾经!)Swift 编译器中的一个错误,并已在 Swift 5.1 中修复。您可以在此处阅读有关该错误的更多信息并查看修复:https://bugs.swift.org/browse/SR-2688

【讨论】:

    猜你喜欢
    • 2015-02-20
    • 1970-01-01
    • 2021-11-06
    • 2012-09-14
    • 2020-07-21
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多