BurntSushi / go-sumtype

A simple utility for running exhaustiveness checks on Go "sum types."
The Unlicense
420 stars 22 forks source link

Check fails if interface is extended by another interface #3

Open atombender opened 7 years ago

atombender commented 7 years ago

Test case:

package main

//go-sumtype:decl Animal

type Animal interface {
    MakeSound()
    sealed()
}

type Dog struct{}

func (*Dog) sealed() {}

func (*Dog) MakeSound() {
    println("WOOF")
}

type Canine interface {
    Animal
    Breed() string
}

func test(animal Animal) {
    switch animal.(type) {
    case *Dog:
        println("is dog")
    }
}

func main() {
    test(&Dog{})
}

Fails:

$ go-sumtype main.go
main.go:24:2: exhaustiveness check failed for sum type 'Animal': missing cases for Canine

I did not expect this to fail, as the switch is exhaustive on all concrete types of the interface and there aren't even any structs implementing the second one. The checks fail even there are structs which implement both or one of them.