Merge pull request #1382 from nspcc-dev/compiler/manifest_methods_fix

compiler: do not convert methods to manifest methods
This commit is contained in:
Roman Khimov 2020-09-03 14:39:51 +03:00 committed by GitHub
commit cf15ca30f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 4 deletions

View file

@ -36,6 +36,8 @@ type MethodDebugInfo struct {
Name DebugMethodName `json:"name"`
// IsExported defines whether method is exported.
IsExported bool `json:"-"`
// IsFunction defines whether method has no receiver.
IsFunction bool `json:"-"`
// Range is the range of smart-contract's opcodes corresponding to the method.
Range DebugRange `json:"range"`
// Parameters is a list of method's parameters.
@ -123,6 +125,7 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
Namespace: c.mainPkg.Pkg.Name(),
},
IsExported: true,
IsFunction: true,
Range: DebugRange{
Start: 0,
End: uint16(c.initEndOffset),
@ -171,6 +174,7 @@ func (c *codegen) methodInfoFromScope(name string, scope *funcScope) *MethodDebu
Namespace: scope.pkg.Name(),
},
IsExported: scope.decl.Name.IsExported(),
IsFunction: scope.decl.Recv == nil,
Range: scope.rng,
Parameters: params,
ReturnType: c.scReturnTypeFromScope(scope),
@ -375,7 +379,7 @@ func (di *DebugInfo) ConvertToManifest(fs smartcontract.PropertyState, events []
}
methods := make([]manifest.Method, 0)
for _, method := range di.Methods {
if method.IsExported && method.Name.Namespace == di.MainPkg {
if method.IsExported && method.IsFunction && method.Name.Namespace == di.MainPkg {
mMethod, err := method.ToManifestMethod()
if err != nil {
return nil, err

View file

@ -42,6 +42,9 @@ func MethodByteArray() []byte { return nil }
func MethodArray() []bool { return nil }
func MethodStruct() struct{} { return struct{}{} }
func unexportedMethod() int { return 1 }
type MyStruct struct {}
func (ms MyStruct) MethodOnStruct() { }
func (ms *MyStruct) MethodOnPointerToStruct() { }
`
info, err := getBuildInfo("foo.go", src)
@ -65,8 +68,10 @@ func unexportedMethod() int { return 1 }
"MethodConcat": "String",
"MethodString": "String", "MethodByteArray": "ByteString",
"MethodArray": "Array", "MethodStruct": "Struct",
"Main": "Boolean",
"unexportedMethod": "Integer",
"Main": "Boolean",
"unexportedMethod": "Integer",
"MethodOnStruct": "Void",
"MethodOnPointerToStruct": "Void",
}
for i := range d.Methods {
name := d.Methods[i].ID

View file

@ -77,7 +77,12 @@ func (c *codegen) newFuncScope(decl *ast.FuncDecl, label uint16) *funcScope {
func (c *codegen) getFuncNameFromDecl(pkgPath string, decl *ast.FuncDecl) string {
name := decl.Name.Name
if decl.Recv != nil {
name = decl.Recv.List[0].Type.(*ast.Ident).Name + "." + name
switch t := decl.Recv.List[0].Type.(type) {
case *ast.Ident:
name = t.Name + "." + name
case *ast.StarExpr:
name = t.X.(*ast.Ident).Name + "." + name
}
}
return c.getIdentName(pkgPath, name)
}