You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ 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.
The text was updated successfully, but these errors were encountered:
lantw44
added a commit
to lantw44/go-sumtype
that referenced
this issue
Apr 17, 2019
Sometimes it is possible for a sum type interface to be implemented by
another interface. For example, we have a sum type called T including
3 variants, A, B, C. We also have an U interface embedding T and thus
implementing T. Assuming that B and C implement U, a type switch
statement can be considered exhaustive if all of A, B, C are listed.
It should also be considered exhaustive if only A and U are listed.
However, go-sumtype does not distinguish between concrete and interface
types. It fails in both cases, requiring all of A, B, C, U to be listed.
It is unlikely to code to be written in this way. U already covers B and
C, and it is unnecessary to list them in a type switch statement. This
commit fixes the problem by handling interfaces specially.
Closes: BurntSushi#1Closes: BurntSushi#3
Test case:
Fails:
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.
The text was updated successfully, but these errors were encountered: