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

types2, go/types: panic when using reflect.TypeOf in unexported struct #48351

Closed
qmuntal opened this issue Sep 13, 2021 · 3 comments
Closed

types2, go/types: panic when using reflect.TypeOf in unexported struct #48351

qmuntal opened this issue Sep 13, 2021 · 3 comments

Comments

@qmuntal
Copy link
Contributor

@qmuntal qmuntal commented Sep 13, 2021

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

go version devel go1.18-ad97d204f0 Sun Sep 12 16:46:58 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-ad97d204f0 Sun Sep 12 16:46:58 2021 +0000
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\_\funcalias\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-build3333664198=/tmp/go-build -gno-record-gcc-switches 

What did you do?

--- p.go

package p

import "reflect"

type foo[T any] struct {}

func (foo[_]) Call() bool {
  return reflect.TypeOf(0) != nil
}

type P0[T any] struct {
  foo foo[T]
}

--- example_test.go

package p_test

import "p"

func Example() {
  var _ = p.P0[string]{}
}

Execute go test example_test.go

What did you expect to see?

No panic

What did you see instead?

# p_test [p.test]
.\main.go:9:23: internal compiler error: missing import reader for reflect.TypeOf

goroutine 1 [running]:
runtime/debug.Stack()
        C:/Users/muntal/sdk/gotip/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x6, 0x0}, {0x181aff1, 0x1c}, {0xc0000dd170, 0x1, 0x1})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/base/print.go:227 +0x154
cmd/compile/internal/base.Fatalf(...)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/typecheck.ImportBody(0xc000646dc0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/typecheck/iimport.go:73 +0x1b9
cmd/compile/internal/typecheck.ImportedBody(0xc000646dc0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/typecheck/func.go:169 +0xad
cmd/compile/internal/inline.oldInline(0xc000624630, 0xc000646dc0, 0x0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:782 +0x53
cmd/compile/internal/inline.mkinlcall(0xc000624630, 0xc000646dc0, 0x8, 0xc00002c870, 0x0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:734 +0xc85
cmd/compile/internal/inline.inlnode({0x19852d8, 0xc000624630}, 0xdd7e8, 0x10d30bf, 0x40)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:591 +0x45d
cmd/compile/internal/inline.InlineCalls.func1({0x19852d8, 0xc000624630})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:513 +0x31
cmd/compile/internal/ir.(*BinaryExpr).editChildren(0xc000404b40, 0xc00005e840)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:204 +0x58
cmd/compile/internal/ir.EditChildren(...)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/inline.inlnode({0x1985080, 0xc000404b40}, 0xdd8f8, 0x10c4de2, 0x1986980)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:570 +0x311
cmd/compile/internal/inline.InlineCalls.func1({0x1985080, 0xc000404b40})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:513 +0x31
cmd/compile/internal/ir.editNodes({0xc000408c10, 0x1, 0xc000649c20}, 0xc00005e840)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1521 +0x74
cmd/compile/internal/ir.(*ReturnStmt).editChildren(0xc000649c20, 0xc000649c20)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1056 +0x53
cmd/compile/internal/ir.EditChildren(...)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/inline.inlnode({0x1986e30, 0xc000649c20}, 0x20, 0x30, 0x209c0ea0108)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:570 +0x311
cmd/compile/internal/inline.InlineCalls.func1({0x1986e30, 0xc000649c20})
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:513 +0x31
cmd/compile/internal/ir.editNodes({0xc000408c00, 0x1, 0x2030000}, 0xc00005e840)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/node_gen.go:1521 +0x74
cmd/compile/internal/ir.(*Func).editChildren(0xc0000ddad8, 0x10cfb87)
        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/inline.InlineCalls(0xc000646f20)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:515 +0xf2
cmd/compile/internal/inline.InlinePackage.func1({0xc000006148, 0x1, 0xc000646f20}, 0x0)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:71 +0x46
cmd/compile/internal/ir.(*bottomUpVisitor).visit(0xc00002c750, 0xc000646f20)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/scc.go:127 +0x2f0
cmd/compile/internal/ir.VisitFuncsBottomUp({0xc00062bac0, 0x2, 0xb}, 0x1837e40)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/ir/scc.go:60 +0x105
cmd/compile/internal/inline.InlinePackage()
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/inline/inl.go:58 +0x33
cmd/compile/internal/gc.Main(0x1837cf8)
        C:/Users/muntal/sdk/gotip/src/cmd/compile/internal/gc/main.go:246 +0xc7d
main.main()
        C:/Users/muntal/sdk/gotip/src/cmd/compile/main.go:55 +0xdd

FAIL    p [build failed]
FAIL

@griesemer

@qmuntal
Copy link
Contributor Author

@qmuntal qmuntal commented Sep 13, 2021

Additional note: The panic does not happen if foo is exported.

Loading

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Sep 13, 2021

Seems duplicated of #48337

Loading

@qmuntal
Copy link
Contributor Author

@qmuntal qmuntal commented Sep 13, 2021

Seems duplicated of #48337

Good catch, it is indeed duplicated.

Loading

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

Successfully merging a pull request may close this issue.

None yet
2 participants