You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
affected/package: go1.20.1 When obtaining a "nil" value after defining an interface, it is not recognized as an empty value during condition checks.
#59521
Closed
vela-security opened this issue
Apr 10, 2023
· 2 comments
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\vela\AppData\Local\go-build
set GOENV=C:\Users\vela\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\vela\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\vela\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\vela\AppData\Local\Temp\go-build236094550=/tmp/go-build -gno-record-gcc-switches
What did you do?
check Nil fail
In the context of Github issues, while inspecting the returned objects of an API, I found that using the API's definition to retrieve a "nil" value doesn't register as an empty value during condition checks. This can easily lead to bugs and errors, so I hope it can be corrected.
package web
import"testing"typeAstruct {
}
func (*A) View() {}
typeShowinterface {
View()
}
funcNewA() *A {
returnnil
}
funcNewShow() Show {
returnNewA()
}
funcTestNil(t*testing.T) {
a:=NewShow()
ifa==nil {
t.Log("a is nil")
return
}
t.Log("a not is nil")
}
test output
API server listening at: 127.0.0.1:61858
=== RUN TestNil
interface_test.go:30: a not is nil
--- PASS: TestNil (0.00s)
What did you expect to see?
a is nil
The text was updated successfully, but these errors were encountered:
vela-security
changed the title
affected/package: go1.20.1 Translation: When obtaining a "nil" value after defining an interface, it is not recognized as an empty value during condition checks.
affected/package: go1.20.1 When obtaining a "nil" value after defining an interface, it is not recognized as an empty value during condition checks.
Apr 10, 2023
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
check Nil fail
In the context of Github issues, while inspecting the returned objects of an API, I found that using the API's definition to retrieve a "nil" value doesn't register as an empty value during condition checks. This can easily lead to bugs and errors, so I hope it can be corrected.
test output
What did you expect to see?
a is nil
The text was updated successfully, but these errors were encountered: