From 640ad101fc63a76b72714076cc4bd3eb99a68636 Mon Sep 17 00:00:00 2001 From: Nishanth Shanmugham Date: Fri, 3 Jun 2022 11:40:42 +0530 Subject: [PATCH] add bugs section in readme for type parameter switch statements --- README.md | 6 ++++++ testdata/xxx/typeparam/main.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 testdata/xxx/typeparam/main.go diff --git a/README.md b/README.md index b843ee8..3992704 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,12 @@ The package provides an `Analyzer` that follows the guidelines in the [`go/analysis`][3] package; this should make it possible to integrate exhaustive with your own analysis driver program. +## Bugs + +`exhaustive` does not report missing cases if the switch statement +switches on a type parameterized type. See [this +issue](https://github.com/nishanths/exhaustive/issues/31) for details. + ## Example Given the enum diff --git a/testdata/xxx/typeparam/main.go b/testdata/xxx/typeparam/main.go new file mode 100644 index 0000000..6efc2da --- /dev/null +++ b/testdata/xxx/typeparam/main.go @@ -0,0 +1,32 @@ +package typeparam + +// Testing instructions: +// $ go build ./cmd/exhaustive +// $ ./exhaustive ./testdata/xxx/typeparam + +type M int + +const ( + A M = iota + B +) + +type N uint + +const ( + C N = iota + D +) + +func foo[T M](v T) { + switch v { + case T(A): + } +} + +func bar[T M | N](v T) { + switch v { + case T(A): + case T(D): + } +}