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 when importing package contains self-referential generic interface type #48306

Closed
cuonglm opened this issue Sep 10, 2021 · 1 comment
Assignees
Labels
Milestone

Comments

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Sep 10, 2021

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

$ go version
go version devel go1.18-b86e8dd0f3 Thu Sep 9 09:06:46 2021 +0000 darwin/arm64

Does this issue reproduce with the latest release?

No

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

go env Output
$ go env

What did you do?

Coming here from #48280, a variant of the program trigger another error:

-- p.go --
package p

type I[T I[T]] interface {
	F() T
}
-- p_test.go --
package p_test

import (
	"testing"

	"p"
)

type S struct{}

func (*S) F() *S { return nil }

func TestP(t *testing.T) {
	var _ p.I[*S] = &S{}
}

What did you expect to see?

Running go test passes.

What did you see instead?

/p_test.go:11:27: internal compiler error: importsym of symbol that already exists: p.I

goroutine 1 [running]:
runtime/debug.Stack()
	/Users/cuonglm/sources/go/src/runtime/debug/stack.go:24 +0x68
cmd/compile/internal/base.FatalfAt({0x1, 0x0}, {0x1031cd645, 0x2b}, {0x1400045cbb8, 0x1, 0x1})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/base/print.go:227 +0x16c
cmd/compile/internal/base.Fatalf(...)
	/Users/cuonglm/sources/go/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/typecheck.importsym({0x1, 0x0}, 0x0, 0xa0, 0x1)
	/Users/cuonglm/sources/go/src/cmd/compile/internal/typecheck/export.go:52 +0x84
cmd/compile/internal/typecheck.importtype({0x8f200, 0x140}, 0x102af89c0)
	/Users/cuonglm/sources/go/src/cmd/compile/internal/typecheck/export.go:65 +0x28
cmd/compile/internal/typecheck.(*importReader).doDecl(0x1400008f200, 0x14000483e00)
	/Users/cuonglm/sources/go/src/cmd/compile/internal/typecheck/iimport.go:326 +0x344
cmd/compile/internal/typecheck.expandDecl({0x1033efd70, 0x14000537540})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/typecheck/iimport.go:61 +0x19c
cmd/compile/internal/typecheck.Resolve({0x1033efd70, 0x14000537540})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/typecheck/typecheck.go:151 +0xe4
cmd/compile/internal/noder.(*irgen).obj(0x14000496000, {0x1033ec1b8, 0x14000489e00})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/object.go:61 +0x170
cmd/compile/internal/noder.(*irgen).typ0(0x14000496000, {0x1033db7d0, 0x14000480bd0})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/types.go:116 +0x2d0
cmd/compile/internal/noder.(*irgen).typ1(0x14000496000, {0x1033db7d0, 0x14000480bd0})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/types.go:60 +0x60
cmd/compile/internal/noder.(*irgen).typ(0x14000496000, {0x1033db7d0, 0x14000480bd0})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/types.go:35 +0x40
cmd/compile/internal/noder.(*irgen).obj(0x14000496000, {0x1033ec258, 0x14000490420})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/object.go:132 +0x84c
cmd/compile/internal/noder.(*irgen).def(0x14000496000, 0x14000411d20)
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/object.go:22 +0xb4
cmd/compile/internal/noder.(*irgen).varDecl(0x14000496000, 0x14000537528, 0x1400012fc80)
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/decl.go:222 +0xbc
cmd/compile/internal/noder.(*irgen).decls(0x803b78101, 0x0, {0x1400010cb50, 0x1, 0x0})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/decl.go:34 +0x11c
cmd/compile/internal/noder.(*irgen).stmt(0x14000496000, {0x1033dc250, 0x14000409050})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/stmt.go:54 +0x118
cmd/compile/internal/noder.(*irgen).stmts(0x1400006fb20, {0x1400010cb60, 0x1, 0x1400012cc58})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/stmt.go:19 +0x9c
cmd/compile/internal/noder.(*irgen).funcBody(0x14000496000, 0x1400043e9a0, 0x1400045d6d8, 0x14000131900, 0x14000131980)
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/func.go:45 +0x224
cmd/compile/internal/noder.(*irgen).funcDecl.func1()
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/decl.go:128 +0x60
cmd/compile/internal/noder.(*irgen).generate(0x14000496000, {0x1400012c428, 0x1, 0xc0})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/irgen.go:263 +0x1cc
cmd/compile/internal/noder.check2({0x1400012c428, 0x1, 0x1})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/irgen.go:93 +0x130
cmd/compile/internal/noder.LoadPackage({0x140001360f0, 0x1, 0x0})
	/Users/cuonglm/sources/go/src/cmd/compile/internal/noder/noder.go:90 +0x2f0
cmd/compile/internal/gc.Main(0x1033cafb0)
	/Users/cuonglm/sources/go/src/cmd/compile/internal/gc/main.go:190 +0xbbc
main.main()
	/Users/cuonglm/sources/go/src/cmd/compile/main.go:55 +0xf8

FAIL	p [build failed]
FAIL
@cuonglm cuonglm self-assigned this Sep 10, 2021
@cuonglm cuonglm added this to the Go1.18 milestone Sep 10, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 10, 2021

Change https://golang.org/cl/349011 mentions this issue: cmd/compile: prevent duplicated import symbol of generic type

Loading

@gopherbot gopherbot closed this in ee91bb8 Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants