gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 06:05:29 26 4
gpt4 key购买 nike

对这个有点惊讶。在 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 编译器中的一个错误,并且已在 Swift 5.1 中修复。您可以在此处阅读有关该错误的更多信息并查看修复程序:https://bugs.swift.org/browse/SR-2688 .

关于swift - 为什么不能在函数闭包类型的类型别名上使用 @autoclosure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40244319/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com