Skip to content

Commit

Permalink
methods: fix exported/unexported bug
Browse files Browse the repository at this point in the history
Fix case where last method was exported after a new exported method
(from a different type) is defined afterwards.
  • Loading branch information
MarioCarrion committed Apr 15, 2019
1 parent 3a705a5 commit 8111de3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (m *MethodsValidator) Validate(v *ast.FuncDecl, fset *token.FileSet) error

if m.lastType != rcvType.Name {
m.sortedTypes.identType = "Type"
m.sortedMethods = sortedNamesValidator{}
if err := validateSorted(&m.sortedTypes, rcvType, false); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func TestMethodsValidator_Validate(t *testing.T) {
"methods_sorted_type_ok.go",
false,
},
{
"OK: sorted exported/unexported",
"methods_sorted_unexported_ok.go",
false,
},
{
"Error: not defined in file",
"methods_not_defined.go",
Expand Down
14 changes: 14 additions & 0 deletions testdata/methods_sorted_unexported_ok.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package testdata

type (
MethodSortedTypeUnexported_A struct{}
MethodSortedTypeUnexported_B struct{}
)

func (MethodSortedTypeUnexported_A) A() {}
func (MethodSortedTypeUnexported_A) B() {}
func (*MethodSortedTypeUnexported_A) c() {}

//-

func (MethodSortedTypeUnexported_B) A() {}

0 comments on commit 8111de3

Please sign in to comment.