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
Closed

cmd/compile: panic on invalid struct initialization #26416

rogpeppe opened this issue Jul 17, 2018 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rogpeppe
Copy link
Contributor

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 the NeedsFix The path to resolution is known, but the work has not been done. label Jul 17, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jul 17, 2018
@gopherbot
Copy link

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

@odeke-em
Copy link
Member

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
Copy link
Member

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

@mvdan has a CL prepared, great!

@mdempsky
Copy link
Member

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

@golang golang locked and limited conversation to collaborators Jul 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants