diff --git a/pkg/compiler/analysis.go b/pkg/compiler/analysis.go index a7489d869..e4211dcb2 100644 --- a/pkg/compiler/analysis.go +++ b/pkg/compiler/analysis.go @@ -285,11 +285,12 @@ func (c *codegen) analyzeFuncUsage() funcUsage { case *ast.FuncDecl: name := c.getFuncNameFromDecl(pkgPath, n) - // exported functions are always assumed to be used + // exported functions and methods are always assumed to be used if isMain && n.Name.IsExported() || isInitFunc(n) || isDeployFunc(n) { diff[name] = true } - if isMain && n.Name.IsExported() { + // exported functions are not allowed to have unnamed parameters + if isMain && n.Name.IsExported() && n.Recv == nil { if n.Type.Params.List != nil { for i, param := range n.Type.Params.List { if param.Names == nil { diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index c9e326865..a3c136a89 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -417,4 +417,13 @@ func TestUnnamedParameterCheck(t *testing.T) { _, _, err := compiler.CompileWithOptions("test.go", strings.NewReader(src), nil) require.NoError(t, err) }) + t.Run("method with unnamed params", func(t *testing.T) { + src := ` + package testcase + type A int + func (rsv A) OnNEP17Payment(_ string, _ int, iface interface{}){} + ` + _, _, err := compiler.CompileWithOptions("test.go", strings.NewReader(src), nil) + require.NoError(t, err) // it's OK for exported method to have unnamed params as it won't be included into manifest + }) }