From ab7f2cb4fbce62ea345bf5bb3679dd810112f9cc Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 29 Apr 2020 16:32:07 +0300 Subject: [PATCH] compiler: fix bug with missing methods parameters Method `methodInfoFromScope(...)` always returned an empty parameters set, so we were missing this information in both .abi.json and .debug.json files. Fixed now. --- pkg/compiler/debug.go | 2 +- pkg/compiler/debug_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/debug.go b/pkg/compiler/debug.go index be1b96d92..0e9162ab7 100644 --- a/pkg/compiler/debug.go +++ b/pkg/compiler/debug.go @@ -112,7 +112,7 @@ func (c *codegen) registerDebugVariable(name string, expr ast.Expr) { func (c *codegen) methodInfoFromScope(name string, scope *funcScope) *MethodDebugInfo { ps := scope.decl.Type.Params params := make([]DebugParam, 0, ps.NumFields()) - for i := range params { + for i := range ps.List { for j := range ps.List[i].Names { params = append(params, DebugParam{ Name: ps.List[i].Names[j].Name, diff --git a/pkg/compiler/debug_test.go b/pkg/compiler/debug_test.go index baecbb09e..96d905c27 100644 --- a/pkg/compiler/debug_test.go +++ b/pkg/compiler/debug_test.go @@ -28,6 +28,9 @@ func methodInt(a string) int { } return 3 } +func methodConcat(a, b string, c string) string{ + return a + b + c +} func methodString() string { return "" } func methodByteArray() []byte { return nil } func methodArray() []bool { return nil } @@ -48,6 +51,7 @@ func methodStruct() struct{} { return struct{}{} } t.Run("return types", func(t *testing.T) { returnTypes := map[string]string{ "methodInt": "Integer", + "methodConcat": "String", "methodString": "String", "methodByteArray": "ByteArray", "methodArray": "Array", "methodStruct": "Struct", "Main": "Boolean", @@ -70,6 +74,39 @@ func methodStruct() struct{} { return struct{}{} } } }) + t.Run("param types", func(t *testing.T) { + paramTypes := map[string][]DebugParam{ + "methodInt": {{ + Name: "a", + Type: "String", + }}, + "methodConcat": { + { + Name: "a", + Type: "String", + }, + { + Name: "b", + Type: "String", + }, + { + Name: "c", + Type: "String", + }, + }, + "Main": {{ + Name: "op", + Type: "String", + }}, + } + for i := range d.Methods { + v, ok := paramTypes[d.Methods[i].Name.Name] + if ok { + require.Equal(t, v, d.Methods[i].Parameters) + } + } + }) + // basic check that last instruction of every method is indeed RET for i := range d.Methods { index := d.Methods[i].Range.End