Skip to content

cmd/compile: panic on interface switch case with invalid name #22063

Closed

Description

@mvdan

Another variation of #21988, this time using an interface type. Found it manually by inspecting the source code as there was a .Val().Interface() use without the appropriate .Type == nil check.

Reproducer:

package p

const X = Wrong(0)

func _() {
        switch interface{}(nil) {
        case X:
        }
}
 $ go build f.go
# command-line-arguments
./f.go:3:11: undefined: Wrong
./f.go:6:9: internal compiler error: unexpected Interface for <nil>

goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
        /home/mvdan/tip/src/runtime/debug/stack.go:24 +0xa7
cmd/compile/internal/gc.Fatalf(0xb79d29, 0x1b, 0xc4203320d8, 0x1, 0x1)
        /home/mvdan/tip/src/cmd/compile/internal/gc/subr.go:181 +0x1e2
cmd/compile/internal/gc.Val.Interface(0x0, 0x0, 0x3, 0xc4203322a8)
        /home/mvdan/tip/src/cmd/compile/internal/gc/const.go:99 +0x2c8
cmd/compile/internal/gc.checkDupExprCases(0xc420308d80, 0xc42000c578, 0x1, 0x1)
        /home/mvdan/tip/src/cmd/compile/internal/gc/swt.go:645 +0x1a9
cmd/compile/internal/gc.typecheckswitch(0xc420308c80)
        /home/mvdan/tip/src/cmd/compile/internal/gc/swt.go:210 +0x12cc
cmd/compile/internal/gc.typecheck1(0xc420308c80, 0x1, 0x4b144b)
        /home/mvdan/tip/src/cmd/compile/internal/gc/typecheck.go:2098 +0xc10d
cmd/compile/internal/gc.typecheck(0xc420308c80, 0x1, 0x3)
        /home/mvdan/tip/src/cmd/compile/internal/gc/typecheck.go:201 +0x694
cmd/compile/internal/gc.typecheckslice(0xc42000c580, 0x1, 0x1, 0x1)
        /home/mvdan/tip/src/cmd/compile/internal/gc/typecheck.go:55 +0x54
cmd/compile/internal/gc.Main(0xb88e40)
        /home/mvdan/tip/src/cmd/compile/internal/gc/main.go:486 +0x1f3c
main.main()
        /home/mvdan/tip/src/cmd/compile/main.go:49 +0x89

Reproduces on both go version devel +0d0c1132f6 Wed Sep 27 04:01:40 2017 +0000 linux/amd64 and 1.9.

Activity

  1. added this to the Go1.10 milestone on Sep 27, 2017
  2. self-assigned this
    on Sep 27, 2017
  3. gopherbot commented on Sep 27, 2017

    @gopherbot
    Contributor

    Change https://golang.org/cl/66450 mentions this issue: cmd/compile: fix another invalid switch case panic

  4. locked and limited conversation to collaborators on Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions