golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

import/path: core

lingdor opened this issue · comments

Go version

go1.22.1 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/zhangxiaoxu/Library/Caches/go-build'
GOENV='/Users/zhangxiaoxu/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/zhangxiaoxu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/zhangxiaoxu/go'
GOPRIVATE=''
GOPROXY='https://goproxy.io,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/85/455rptmx1d1g7s_qhnhnc9x00000gn/T/go-build3269171821=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

type tt struct {
}

func TestNIL(t *testing.T) {

	var a any
	var er *tt = nil
	a = er
	if a == nil {
		fmt.Println("expected")
	} else {
		t.Errorf("didn't expected: %+v", a)
	}
}

What did you see happen?

xiaoke_test.go:38: didn't expected: <nil>

--- FAIL: TestNIL (0.00s)
FAIL

What did you expect to see?

output:expected

This is correct result.
Resaon see https://go.dev/doc/faq#nil_error

It's right. a real type is * * tt .