Go 1.18 迁移问题 — 无法将 ‘nil’ 转换为类型 ‘any’

huangapple go评论215阅读模式
英文:

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版本的发布说明,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?

答案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.

huangapple
  • 本文由 发表于 2022年3月30日 19:11:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/71676165.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定