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:
parent
87b0e76a8c
commit
592fd068b1
2 changed files with 38 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue