mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 03:47:18 +00:00
compiler: properly retrieve name of generic functions
Fix panic described in #3040. Ref. #2376. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
5c6a111d00
commit
415d44792a
1 changed files with 18 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
package compiler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/types"
|
||||
)
|
||||
|
@ -85,7 +86,23 @@ func (c *codegen) getFuncNameFromDecl(pkgPath string, decl *ast.FuncDecl) string
|
|||
case *ast.Ident:
|
||||
name = t.Name + "." + name
|
||||
case *ast.StarExpr:
|
||||
name = t.X.(*ast.Ident).Name + "." + name
|
||||
switch t.X.(type) {
|
||||
case *ast.Ident:
|
||||
name = t.X.(*ast.Ident).Name + "." + name
|
||||
case *ast.IndexExpr:
|
||||
// Generic func declaration receiver: func (x *Pointer[T]) Load() *T
|
||||
name = t.X.(*ast.IndexExpr).X.(*ast.Ident).Name + "." + name
|
||||
default:
|
||||
panic(fmt.Errorf("unexpected function `%s` receiver type: %T", name, t.X))
|
||||
}
|
||||
case *ast.IndexExpr:
|
||||
switch t.X.(type) {
|
||||
case *ast.Ident:
|
||||
// Generic func declaration receiver: func (x Pointer[T]) Load() *T
|
||||
name = t.X.(*ast.Ident).Name + "." + name
|
||||
default:
|
||||
panic(fmt.Errorf("unexpected function `%s` receiver type: %T", name, t.X))
|
||||
}
|
||||
}
|
||||
}
|
||||
return c.getIdentName(pkgPath, name)
|
||||
|
|
Loading…
Reference in a new issue