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.
This commit is contained in:
Anna Shaleva 2020-04-29 16:32:07 +03:00
parent 861aca1547
commit ab7f2cb4fb
2 changed files with 38 additions and 1 deletions

View file

@ -112,7 +112,7 @@ func (c *codegen) registerDebugVariable(name string, expr ast.Expr) {
func (c *codegen) methodInfoFromScope(name string, scope *funcScope) *MethodDebugInfo { func (c *codegen) methodInfoFromScope(name string, scope *funcScope) *MethodDebugInfo {
ps := scope.decl.Type.Params ps := scope.decl.Type.Params
params := make([]DebugParam, 0, ps.NumFields()) params := make([]DebugParam, 0, ps.NumFields())
for i := range params { for i := range ps.List {
for j := range ps.List[i].Names { for j := range ps.List[i].Names {
params = append(params, DebugParam{ params = append(params, DebugParam{
Name: ps.List[i].Names[j].Name, Name: ps.List[i].Names[j].Name,

View file

@ -28,6 +28,9 @@ func methodInt(a string) int {
} }
return 3 return 3
} }
func methodConcat(a, b string, c string) string{
return a + b + c
}
func methodString() string { return "" } func methodString() string { return "" }
func methodByteArray() []byte { return nil } func methodByteArray() []byte { return nil }
func methodArray() []bool { return nil } func methodArray() []bool { return nil }
@ -48,6 +51,7 @@ func methodStruct() struct{} { return struct{}{} }
t.Run("return types", func(t *testing.T) { t.Run("return types", func(t *testing.T) {
returnTypes := map[string]string{ returnTypes := map[string]string{
"methodInt": "Integer", "methodInt": "Integer",
"methodConcat": "String",
"methodString": "String", "methodByteArray": "ByteArray", "methodString": "String", "methodByteArray": "ByteArray",
"methodArray": "Array", "methodStruct": "Struct", "methodArray": "Array", "methodStruct": "Struct",
"Main": "Boolean", "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 // basic check that last instruction of every method is indeed RET
for i := range d.Methods { for i := range d.Methods {
index := d.Methods[i].Range.End index := d.Methods[i].Range.End