compiler: allow unnamed params for exported methods
Adjust the result of #2601.
This commit is contained in:
parent
5d5455312a
commit
171364f07f
2 changed files with 12 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue