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

cmd/compile: nil pointer dereference #57715

Closed
richsoap opened this issue Jan 10, 2023 · 1 comment
Closed

cmd/compile: nil pointer dereference #57715

richsoap opened this issue Jan 10, 2023 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@richsoap
Copy link

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

$ go version
go version go1.19.4 linux/amd64

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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/***/.cache/go-build"
GOENV="/home/***/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/***/go/pkg/mod"
GONOPROXY="***"
GONOSUMDB="***"
GOOS="linux"
GOPATH="/home/***/go"
GOPRIVATE="***"
GOPROXY="***"
GOROOT="/usr/local/lib/go"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/local/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/***/workspace/golang/***/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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build868479349=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I've written a simple reproduce code. Why not read the code?

The following code will cause 'internal compiler error'.
playground link

package main

import "fmt"

type GreenHand interface {
	SayHi()
}

type GreenHands[G GreenHand] []G

func (gs GreenHands[G]) SayHi() {
	for _, g := range gs {
		g.SayHi()
	}
}

type IntGreenHand[A any] struct {
	ExampleGreenHand[A, int64]
}

type ExampleGreenHand[A, B any] struct{}

func (e ExampleGreenHand[A, B]) SayHi() {
	fmt.Println("Hello!")
}

func main() {
	make(GreenHands[IntGreenHand[string]], 1).SayHi()
}

After add this method, everything looks good.
playground link

func (g IntGreenHand[A]) SayHi() {
	g.ExampleGreenHand.SayHi()
}

What did you expect to see?

I expected to see "Hello!" in my terminal without adding method.

What did you see instead?

I saw this message when I compiled 'panic code'.

./prog.go:23:4: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

Go build failed.
@richsoap richsoap changed the title affected/package: go compiler panic during processing generic slice affected/package: go compiler paniced during processing generic slice Jan 10, 2023
@richsoap richsoap changed the title affected/package: go compiler paniced during processing generic slice panic/compiler: go compiler paniced during processing generic slice Jan 10, 2023
@seankhliao seankhliao changed the title panic/compiler: go compiler paniced during processing generic slice cmd/compile: mil pointer dereference Jan 10, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 10, 2023
@cagedmantis cagedmantis changed the title cmd/compile: mil pointer dereference cmd/compile: nil pointer dereference Jan 10, 2023
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 10, 2023
@randall77
Copy link
Contributor

This works correctly on tip.
We're not currently backporting fixes to the pre-unified generics implementation, so I'm going to close this.
Thanks for the report though.

@randall77 randall77 added the generics Issue is related to generics label Jan 10, 2023
@golang golang locked and limited conversation to collaborators Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants