Skip to content

cmd/compile: panic on invalid struct initialization #26416

@rogpeppe

Description

@rogpeppe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions