go-sumtype icon indicating copy to clipboard operation
go-sumtype copied to clipboard

check: fix false positive when an interface implements a sum type

Open lantw44 opened this issue 5 years ago • 2 comments

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: https://github.com/BurntSushi/go-sumtype/issues/1 Closes: https://github.com/BurntSushi/go-sumtype/issues/3

lantw44 avatar Apr 17 '19 08:04 lantw44

Ping again ... I hope you have seen my reply. Do you have any new comment? There has been no activity on the pull request for 3 weeks.

lantw44 avatar May 09 '19 02:05 lantw44

Because I'm busy. Please be patient. I don't have a reply yet because I need to try this out for myself.

BurntSushi avatar May 09 '19 10:05 BurntSushi