这是一个简单的例子:
package main
import "fmt"
type A struct {
Name *string
}
type B struct {
A *A
}
func main() {
deref(&B{})
}
func deref(b *B) {
fmt.Println(*b.A.Name) // panic: nil pointer dereference
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种可以找到此类情况的解决方案。Jetbrains Goland 中有一个“nillness 检查”,但它不会检查这个问题。