1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-09 13:37:14 +02:00

Avoid false positives when returning interface values (#6)

* Use subtests

* Make unexported-return type check

* Avoid false positives when returning interface values

Fixes #5.
This commit is contained in:
Tamir Duberstein 2018-06-11 14:22:33 -04:00 committed by Minko Gechev
parent 1b2ffe282e
commit 32df8ca880

View File

@ -84,8 +84,16 @@ func (w lintUnexportedReturn) Visit(n ast.Node) ast.Visitor {
func exportedType(typ types.Type) bool {
switch T := typ.(type) {
case *types.Named:
obj := T.Obj()
switch {
// Builtin types have no package.
return T.Obj().Pkg() == nil || T.Obj().Exported()
case obj.Pkg() == nil:
case obj.Exported():
default:
_, ok := T.Underlying().(*types.Interface)
return ok
}
return true
case *types.Map:
return exportedType(T.Key()) && exportedType(T.Elem())
case interface {