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: internal compiler error: typecheckclosure: var fn does not have decldepth assigned #17588

Closed
xlab opened this issue Oct 25, 2016 · 3 comments
Milestone

Comments

@xlab
Copy link

xlab commented Oct 25, 2016

What version of Go are you using?

$ go version
go version go1.7.1 darwin/amd64
$ go version
go version go1.7.3 darwin/amd64

What operating system and processor architecture are you using?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xlab/Documents/dev/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dr/2vrbtj0j7kl1yy32kp5cpn040000gn/T/go-build908632565=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

The following code fails to compile:

package main

type Foo func(b Bar)

func Bar(fn Foo) {
    func() {
        fn(nil)
    }()
}

https://play.golang.org/p/_5BweYoX9p

What did you expect to see?

A compiler error, describing the case.

What did you see instead?

A panic stacktrace from the compiler, the compilation aborts.

$ go run a.go
# command-line-arguments
./a.go:3: Bar is not a type
./a.go:6: internal compiler error: typecheckclosure: var fn does not have decldepth assigned

goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
    /usr/local/go/src/runtime/debug/stack.go:24 +0x79
cmd/compile/internal/gc.Fatalf(0x50d877, 0x39, 0xc42042bb40, 0x1, 0x1)
    /usr/local/go/src/cmd/compile/internal/gc/subr.go:165 +0x248
cmd/compile/internal/gc.typecheckclosure(0xc42041c750, 0xe)
    /usr/local/go/src/cmd/compile/internal/gc/closure.go:113 +0x476
cmd/compile/internal/gc.typecheck1(0xc42041c750, 0xe, 0xc42041c510)
    /usr/local/go/src/cmd/compile/internal/gc/typecheck.go:1895 +0x582d
cmd/compile/internal/gc.typecheck(0xc42041c750, 0xe, 0x0)
    /usr/local/go/src/cmd/compile/internal/gc/typecheck.go:188 +0x654
cmd/compile/internal/gc.typecheck1(0xc42041c990, 0x1, 0x8)
    /usr/local/go/src/cmd/compile/internal/gc/typecheck.go:1200 +0x3cb4
cmd/compile/internal/gc.typecheck(0xc42041c990, 0x1, 0x0)
    /usr/local/go/src/cmd/compile/internal/gc/typecheck.go:188 +0x654
cmd/compile/internal/gc.typecheckslice(0xc420030798, 0x1, 0x1, 0x1)
    /usr/local/go/src/cmd/compile/internal/gc/typecheck.go:49 +0x57
cmd/compile/internal/gc.Main()
    /usr/local/go/src/cmd/compile/internal/gc/main.go:389 +0x178d
cmd/compile/internal/amd64.Main()
    /usr/local/go/src/cmd/compile/internal/amd64/galign.go:93 +0x2fa
main.main()
    /usr/local/go/src/cmd/compile/main.go:33 +0x2a3
@rakyll rakyll added this to the Go1.8 milestone Oct 25, 2016
@josharian
Copy link
Contributor

cc @mdempsky

@gopherbot
Copy link

CL https://golang.org/cl/32415 mentions this issue.

@JayNakrani
Copy link
Contributor

JayNakrani commented Oct 30, 2016

Name.Decldepth is 0 in typecheckclosure(), because in case of Func.Nname.Type==nil, [typecheckfunc() returns](https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/typecheck.go#L3421&q="if t == nil {") without [initializing the Decldepth](https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/typecheck.go#L3432&q="ln.Name.Decldepth = 1") for func's autodcls.

After golang.org/cl/32415:

$ ../pkg/tool/linux_amd64/compile ../test/fixedbugs/issue17588.go 
../test/fixedbugs/issue17588.go:9: Hehe is not a type

@golang golang locked and limited conversation to collaborators Oct 31, 2017
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

5 participants