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: panic on generic type switch #48838

Closed
qmuntal opened this issue Oct 7, 2021 · 2 comments
Closed

cmd/compile: panic on generic type switch #48838

qmuntal opened this issue Oct 7, 2021 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@qmuntal
Copy link
Contributor

qmuntal commented Oct 7, 2021

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

go version devel go1.18-6f74ed06c5 Thu Oct 7 03:41:40 2021 +0000 windows/amd64

Does this issue reproduce with the latest release?

Only in tip

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

go env Output
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\muntal\AppData\Local\go-build
set GOENV=C:\Users\muntal\AppData\Roaming\go\env  
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\muntal\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\muntal\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\muntal\sdk\gotip
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\muntal\sdk\gotip\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.18-6f74ed06c5 Thu Oct 7 03:41:40 2021 +0000
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\_\stateless\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\muntal\AppData\Local\Temp\go-build2096857021=/tmp/go-build -gno-record-gcc-switches 

What did you do?

Crafted this minimal reproducer from a much complex code base.

== main.go ==

package main

func main() {
  check[string]()
}

func check[T any]() {
  var result setter[T]
  switch result.(type) {
  case fooA[T]:
  case fooB[T]:
  }
}

type setter[T any] interface {
  Set(T)
}

type fooA[T any] struct{}

func (fooA[T]) Set(T) {}

type fooB[T any] struct{}

func (fooB[T]) Set(T) {}

gotip tool compile main.go

What did you expect to see?

Successful compilation

What did you see instead?

panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
cmd/compile/internal/noder.(*irgen).dictPass.func1({0x14c6920, 0xc0003f9020})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1302 +0x100b
cmd/compile/internal/ir.editCaseClauses({0xc00005d140, 0x2, 0x14c7e38}, 0xc00041a9a0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1449 +0x62
cmd/compile/internal/ir.(*SwitchStmt).editChildren(0xc000134b00, 0xc00041a9a0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1320 +0xb4
cmd/compile/internal/ir.EditChildren(...)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*irgen).dictPass.func1({0x14c8b80, 0xc000134b00})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1185 +0x74
cmd/compile/internal/ir.editNodes({0xc0003feff0, 0x3, 0x0}, 0xc00041a9a0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1521 +0x74
cmd/compile/internal/ir.(*Func).editChildren(0xa7b267, 0x10)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/func.go:153 +0x2e
cmd/compile/internal/ir.EditChildren(...)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*irgen).dictPass.func1({0x14c71b8, 0xc0003f4c60})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1185 +0x74
cmd/compile/internal/noder.(*irgen).dictPass(0xc000404000, 0xc00040e150)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1319 +0x126
cmd/compile/internal/noder.(*irgen).stencil(0xc000404000)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:240 +0x51b
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:307 +0x359
cmd/compile/internal/noder.check2({0xc000006448, 0x1, 0x1})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:93 +0x175
cmd/compile/internal/noder.LoadPackage({0xc00005e3d0, 0x1, 0x0})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x13934c8)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        C:/Users/muntal/sdk/gotip/src/cmd/compile/main.go:55 +0xdd
PS C:\_\stateless> gotip tool compile main.go        
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
cmd/compile/internal/noder.(*irgen).dictPass.func1({0x14c6920, 0xc0003f9020})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1302 +0x100b
cmd/compile/internal/ir.editCaseClauses({0xc00005d160, 0x2, 0x14c7e38}, 0xc00041a9a0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1449 +0x62
cmd/compile/internal/ir.(*SwitchStmt).editChildren(0xc000134b00, 0xc00041a9a0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1320 +0xb4
cmd/compile/internal/ir.EditChildren(...)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*irgen).dictPass.func1({0x14c8b80, 0xc000134b00})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1185 +0x74
cmd/compile/internal/ir.editNodes({0xc0003feff0, 0x3, 0x0}, 0xc00041a9a0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1521 +0x74
cmd/compile/internal/ir.(*Func).editChildren(0xa7b267, 0x10)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/func.go:153 +0x2e
cmd/compile/internal/ir.EditChildren(...)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*irgen).dictPass.func1({0x14c71b8, 0xc0003f4c60})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1185 +0x74
cmd/compile/internal/noder.(*irgen).dictPass(0xc000400000, 0xc00040e180)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:1319 +0x126
cmd/compile/internal/noder.(*irgen).stencil(0xc000400000)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:240 +0x51b
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:307 +0x359
cmd/compile/internal/noder.LoadPackage({0xc00005e3d0, 0x1, 0x0})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x13934c8)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        C:/Users/muntal/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

@cuonglm @griesemer

@cuonglm
Copy link
Member

cuonglm commented Oct 7, 2021

It seems https://go-review.googlesource.com/c/go/+/349613 causes this failed.

cc @danscales

@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 7, 2021
@cuonglm cuonglm added this to the Go1.18 milestone Oct 7, 2021
@gopherbot
Copy link

Change https://golang.org/cl/354549 mentions this issue: cmd/compile: fix the index variable is shadowed in dictPass

@golang golang locked and limited conversation to collaborators Oct 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants