diff --git a/checkers/caseOrder_checker.go b/checkers/caseOrder_checker.go index 3da6f5c87..1ef4b53b7 100644 --- a/checkers/caseOrder_checker.go +++ b/checkers/caseOrder_checker.go @@ -57,6 +57,10 @@ func (c *caseOrderChecker) checkTypeSwitch(s *ast.TypeSwitchStmt) { cc := cc.(*ast.CaseClause) for _, x := range cc.List { typ := c.ctx.TypesInfo.TypeOf(x) + if typ == nil { + c.warnTypeImpl(cc, x) + return + } for _, iface := range ifaces { if types.Implements(typ, iface.typ) { c.warnTypeSwitch(cc, x, iface.node) @@ -74,6 +78,10 @@ func (c *caseOrderChecker) warnTypeSwitch(cause, concrete, iface ast.Node) { c.ctx.Warn(cause, "case %s must go before the %s case", concrete, iface) } +func (c *caseOrderChecker) warnTypeImpl(cause, concrete ast.Node) { + c.ctx.Warn(cause, "type is not defined %s", concrete) +} + func (c *caseOrderChecker) checkSwitch(s *ast.SwitchStmt) { // TODO(Quasilyte): can handle expression cases that overlap. // Cases that have narrower value range should go before wider ones. diff --git a/checkers/testdata/caseOrder/positive_tests.go b/checkers/testdata/caseOrder/positive_tests.go index 02cdd3bd1..f631a5db9 100644 --- a/checkers/testdata/caseOrder/positive_tests.go +++ b/checkers/testdata/caseOrder/positive_tests.go @@ -46,4 +46,9 @@ func typeSwitches(x interface{}) { case *myReader: default: } + + switch x.(type) { + /*! type is not defined myType */ + case myType: + } } diff --git a/go-critic b/go-critic new file mode 160000 index 000000000..b93735691 --- /dev/null +++ b/go-critic @@ -0,0 +1 @@ +Subproject commit b9373569160643640c0cfa345c5b6c8d549ad36d