Skip to content

proposal: spec: non-empty interface type for multiple case in type switch #460

@krasin

Description

@krasin
Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
Try to compile attached file. It will fail with:
main.go:13: v.IsNil undefined (type reflect.Value has no field IsNil)

What is the expected output? What do you see instead?
It would be nice if it is compilable. The core of example is the switch:

var a reflect.Value
switch v := a.(type) {
case *reflect.InterfaceValue,
        *reflect.PtrValue:
        if v.IsNil() {
                fmt.Printf("null")
        }
}
Both reflect.InterfaceValue and reflect.PtrValue has IsNil method but if 
compiler sees the multiple type case, it suppose that v is just 
reflect.Value and could not find IsNil method.

What is your $GOOS?  $GOARCH?
linux, amd64

Which revision are you using?  (hg identify)

affe0f093696+ tip

Please provide any additional information below.
This issue was discussed during review of 
http://golang.org/cl/179125 with Russ Cox.

Attachments:

  1. main.go (203 bytes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeLanguageChangeSuggested changes to the Go languagev2An incompatible library change

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions