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: got nil for t (1.7.5, 1.8.1 and tip) #20185

Closed
ALTree opened this issue Apr 30, 2017 · 5 comments

Comments

Projects
None yet
5 participants
@ALTree
Copy link
Member

commented Apr 30, 2017

The following program:

package p

func F() {
	switch t := nil.(type) {
	default:
		_ = t
	}
}

crashes the go1.7.5, go1.8.1 and tip compilers with the following error:

# command-line-arguments
./prova.go:4: cannot type switch on non-interface value nil
./prova.go:4: internal compiler error: got nil for t

goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x79
cmd/compile/internal/gc.Fatalf(0xaba22d, 0xd, 0xc420309a18, 0x2, 0x2)
	/usr/local/go/src/cmd/compile/internal/gc/subr.go:167 +0x226
cmd/compile/internal/gc.typecheckdef(0xc420338f30, 0xc42001f560)
	/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:3781 +0x41a
cmd/compile/internal/gc.typecheck1(0xc420338f30, 0x22, 0x90)
	/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:266 +0xdd5b
cmd/compile/internal/gc.typecheck(0xc420338f30, 0x22, 0xc42030aab0)
	/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:188 +0x608
cmd/compile/internal/gc.typecheckswitch(0xc420338c60)
	/usr/local/go/src/cmd/compile/internal/gc/swt.go:185 +0x2b8
cmd/compile/internal/gc.typecheck1(0xc420338c60, 0x1, 0x4)
	/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:2068 +0xc7a8
cmd/compile/internal/gc.typecheck(0xc420338c60, 0x1, 0x3)
	/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:188 +0x608
cmd/compile/internal/gc.typecheckslice(0xc42000c588, 0x1, 0x1, 0x1)
	/usr/local/go/src/cmd/compile/internal/gc/typecheck.go:49 +0x4e
cmd/compile/internal/gc.Main()
	/usr/local/go/src/cmd/compile/internal/gc/main.go:374 +0x1938
main.main()
	/usr/local/go/src/cmd/compile/main.go:50 +0xfe

@ALTree ALTree added the NeedsFix label Apr 30, 2017

@bradfitz bradfitz added this to the Go1.9 milestone Apr 30, 2017

@bradfitz

This comment has been minimized.

Copy link
Member

commented Apr 30, 2017

@tzneal

This comment has been minimized.

Copy link
Member

commented Apr 30, 2017

It happens with type switching on anything untyped:

const x = 1

func G() {
	switch t := x.(type) {
	default:
	}
}

Testing a fix now.

@josharian

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2017

@tzneal awesome. There's an outside chance that your fix might also address #19977 -- worth checking, anyway.

@ALTree

This comment has been minimized.

Copy link
Member Author

commented Apr 30, 2017

If it doesn't, I have a patch for #19977 (in fact, I found this bug while working on that one).

@gopherbot

This comment has been minimized.

Copy link

commented Apr 30, 2017

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

@gopherbot gopherbot closed this in cee5cd5 Apr 30, 2017

@golang golang locked and limited conversation to collaborators Apr 30, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.