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 invalid struct initialization #26416

Closed
rogpeppe opened this issue Jul 17, 2018 · 4 comments

Comments

Projects
None yet
5 participants
@rogpeppe
Copy link
Contributor

commented Jul 17, 2018

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

go version devel +b59b42c Tue Jul 17 10:07:18 2018 +0000 linux/amd64

What did you do?

Compile this:

package main

type A struct {
	X int
}

type B struct {
	*A
}

func main() {
	_ = B{X: 0}
}

What did you expect to see?

./bug.go:12:9: unknown field 'X' in struct literal of type B

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0xb964d8]

goroutine 1 [running]:
cmd/compile/internal/gc.typecheckcomplit(0xc000360380, 0x0)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:3155 +0x14f8
cmd/compile/internal/gc.typecheck1(0xc000360380, 0x2, 0xc00031b0e0)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:859 +0x4ee1
cmd/compile/internal/gc.typecheck(0xc000360380, 0x2, 0xc00031b0e0)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:238 +0x6ad
cmd/compile/internal/gc.typecheckas(0xc000360300)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:3336 +0xa4
cmd/compile/internal/gc.typecheck1(0xc000360300, 0x1, 0xcb547b)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:1985 +0x3735
cmd/compile/internal/gc.typecheck(0xc000360300, 0x1, 0x3)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:238 +0x6ad
cmd/compile/internal/gc.typecheckslice(0xc00000c5f0, 0x1, 0x1, 0x1)
	/home/rog/go/src/cmd/compile/internal/gc/typecheck.go:68 +0x50
cmd/compile/internal/gc.Main(0xcd4b28)
	/home/rog/go/src/cmd/compile/internal/gc/main.go:518 +0x2059
main.main()
	/home/rog/go/src/cmd/compile/main.go:51 +0x96

@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jul 17, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Jul 17, 2018

Change https://golang.org/cl/124395 mentions this issue: cmd/compile: fix crash on invalid struct literal

@odeke-em

This comment has been minimized.

Copy link
Member

commented Jul 17, 2018

This issue is actually a regression, on Go1.10 it returns the expected error as per
https://play.golang.org/p/WqHsGsJTeAs
screen shot 2018-07-17 at 1 42 26 pm

whereas on tip it trips out as reported

@odeke-em odeke-em modified the milestones: Go1.12, Go1.11 Jul 17, 2018

@odeke-em

This comment has been minimized.

Copy link
Member

commented Jul 17, 2018

Confirmed that this was introduced by CL 97076 aka commit 42ecf39#diff-7728aae3914e92bdec496b35e670668c /cc @ChrisALiles @mdempsky

@mvdan has a CL prepared, great!

@mdempsky

This comment has been minimized.

Copy link
Member

commented Jul 17, 2018

@odeke-em Thanks for identifying the regression root cause.

@gopherbot gopherbot closed this in ba6974f Jul 18, 2018

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