为什么不能在类型别名上使用@autoclosure而不是函数闭包类型?

问题描述 投票:4回答:1

[金达对此感到惊讶。在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

为什么不呢?似乎这是同一件事的别名,不是吗?

swift swift3 type-alias
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.