Skip to content

cmd/compile: panic on invalid struct initialization #26416

Closed

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

Activity

  1. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Jul 17, 2018
  2. added this to the Go1.12 milestone on Jul 17, 2018
  3. gopherbot commented on Jul 17, 2018

    @gopherbot
    Contributor

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

  4. odeke-em commented on Jul 17, 2018

    @odeke-em
    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

  5. modified the milestones: Go1.12, Go1.11 on Jul 17, 2018
  6. odeke-em commented on Jul 17, 2018

    @odeke-em
    Member

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

    @mvdan has a CL prepared, great!

  7. mdempsky commented on Jul 17, 2018

    @mdempsky
    Contributor

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

  8. locked and limited conversation to collaborators on Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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