英文:
Go 1.18 migration issues — Cannot convert 'nil' to type 'any'
问题
我将您的代码库更新到了Go 1.18版本。整体看起来都很好,但在几个地方,我发现了以下问题。
defer func() {
if e := recover(); e != nil {
...
}
}()
编译失败,报错信息为:
无法将'nil'转换为类型'any'
相同的代码在Go 1.17版本下是正常工作的。根据Go 1.18版本的发布说明,any
是interface{}
(泛型)的内置类型别名。
发生了什么情况?
英文:
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?
答案1
得分: 12
问题出在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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论