From 70a58b6522636f45657df20e0ca20c85b685a46c Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 1 Sep 2020 19:06:32 +0300 Subject: [PATCH] compiler: do not convert methods to manifest methods Close #1381 --- pkg/compiler/debug.go | 6 +++++- pkg/compiler/debug_test.go | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index 6aeca7e9f..e4ef96e3d 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -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 diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index 95c778e8c..6223e59e4 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -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