From c61cda06808b4fbc0bd9ef29bb8cba58c6813293 Mon Sep 17 00:00:00 2001 From: Nishanth Shanmugham Date: Fri, 19 Nov 2021 20:38:06 +0530 Subject: [PATCH] add test case for uppercase inner member --- exhaustive.go | 9 ++++++--- testdata/src/general/x/general.go | 6 ++++++ testdata/src/general/y/y.go | 8 ++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/exhaustive.go b/exhaustive.go index 31aa42b..239577b 100644 --- a/exhaustive.go +++ b/exhaustive.go @@ -48,6 +48,10 @@ denoting constants (e.g. somepkg.Grassland) listed in a switch statement's cases can contribute towards satisfying exhaustiveness. Literal values, struct fields, re-assignable variables, etc. will not. +The analyzer will produce a diagnostic about unhandled enum members if the +required memebers are not listed in a switch statement's cases (this applies +even if the switch statement has a 'default' case). + Type aliases The analyzer handles type aliases for an enum type in the following manner. @@ -248,11 +252,10 @@ func run(pass *analysis.Pass) (interface{}, error) { exportFact(pass, typ, members) } - cfg := config{ + checkSwitchStatements(pass, inspect, config{ defaultSignifiesExhaustive: fDefaultSignifiesExhaustive, checkGeneratedFiles: fCheckGenerated, ignoreEnumMembers: fIgnoreEnumMembers.value(), - } - checkSwitchStatements(pass, inspect, cfg) + }) return nil, nil } diff --git a/testdata/src/general/x/general.go b/testdata/src/general/x/general.go index 5fdb9c7..c398594 100644 --- a/testdata/src/general/x/general.go +++ b/testdata/src/general/x/general.go @@ -187,3 +187,9 @@ func _r(d Direction) { case 5: } } + +func _s(u bar.Uppercase) { + switch u { + case bar.ReallyExported: + } +} diff --git a/testdata/src/general/y/y.go b/testdata/src/general/y/y.go index d11ce1c..93ce213 100644 --- a/testdata/src/general/y/y.go +++ b/testdata/src/general/y/y.go @@ -10,3 +10,11 @@ const ( ) type IntWrapper int + +type Uppercase int // want Uppercase:"^ReallyExported$" +const ReallyExported Uppercase = 1 + +func f() { + type AliasForUppercase = Uppercase + const NotReallyExported AliasForUppercase = 2 // not exported, and in fact not even a member of enum type Uppercase +}