Go 1.18 迁移问题 ߞ无法转换“nil”;输入“任何”

发布于 2025-01-17 18:13:40 字数 328 浏览 2 评论 0原文

我将代码库更新为 Go 1.18。一切看起来都很棒,但在一些地方,我发现了以下问题。

defer func() {
    if e := recover() ; e!=nil {
        ...
    }
}()

编译失败并显示:

无法将“nil”转换为“any”类型

相同的代码在 Go 1.17 中运行良好。根据 Go 1.18 发行说明,anyinterface{}(泛型)的内置类型别名,

这是怎么回事?

I updated my codebase to Go 1.18. It all looks great, but in a few places, I found the following issues.

defer func() {
    if e := recover() ; e!=nil {
        ...
    }
}()

Compilation is failing with:

Cannot convert 'nil' to type 'any'

The same code was working good with Go 1.17. Based on Go 1.18 Release notes, any is a built-in type of alias for interface{} (Generics)

What is going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2025-01-24 18:13:40

问题出在 IDE 上。 IntelliJ Goland 2021.2.4

我可以从命令行和 playground 构建代码。

The issue is with the IDE. IntelliJ Goland 2021.2.4

I can build the code from the command line and in the playground.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文