Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types, types2: Syntax (interface vs nil struct) This example breaks the concept of passing nil values to interface #54470

Closed
vorishirne opened this issue Aug 16, 2022 · 1 comment

Comments

@vorishirne
Copy link

What version of Go are you using (go version)?

$ go version
go version 1.18.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vorishirne/.cache/go-build"
GOENV="/home/vorishirne/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/vorishirne/go/pkg/mod"
GONOPROXY="gitlab.private.aws.cradlepointecm.com"
GONOSUMDB="gitlab.private.aws.cradlepointecm.com"
GOOS="linux"
GOPATH="/home/vorishirne/go"
GOPRIVATE="gitlab.private.aws.cradlepointecm.com"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/vo/wo/repository/aaorg/ncx-auth/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""                                                                                                                               
CGO_CXXFLAGS="-g -O2"                                                                                                                         
CGO_FFLAGS="-g -O2"                                                                                                                           
CGO_LDFLAGS="-g -O2"                                                                                                                          
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2039916513=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"fmt"
)


type IO interface {
	Foo()
}

type IOImplementation struct {
}

func (e IOImplementation) Foo() {
}

func returnNilIO() *IOImplementation {
	return nil
}


func main() {
	var io IO
	io = returnNilIO()
	if io != nil {
		fmt.Printf("io is %v", io)
	}
}

What did you expect to see?

What did you see instead?

io is nil

Is this phenomena documented somewhere? How to pass nil to an interface in this case.

@mengzhuo mengzhuo changed the title affected/package: Syntax (interface vs nil struct) This example breaks the concept of passing nil values to interface go/types, types2: Syntax (interface vs nil struct) This example breaks the concept of passing nil values to interface Aug 16, 2022
@mvdan
Copy link
Member

mvdan commented Aug 16, 2022

https://go.dev/doc/faq#nil_error

The Go project doesn't use the issue tracker for questions. See https://golang.org/wiki/Questions.

@mvdan mvdan closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2022
@golang golang locked and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants