compiler: properly set extended type name for unnamed structs

After the struct was registered as "unnamed", it has the own unique name.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2023-05-25 18:45:59 +03:00
parent 0195aae824
commit 6379bcc15a
2 changed files with 8 additions and 16 deletions

View file

@ -95,7 +95,7 @@ type SomeMapEvent struct {
// SomeStructEvent represents "SomeStruct" event emitted by the contract.
type SomeStructEvent struct {
S []any
S *Unnamed
}
// SomeArrayEvent represents "SomeArray" event emitted by the contract.
@ -1052,20 +1052,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
err error
)
index++
e.S, err = func (item stackitem.Item) ([]any, error) {
arr, ok := item.Value().([]stackitem.Item)
if !ok {
return nil, errors.New("not an array")
}
res := make([]any, len(arr))
for i := range res {
res[i], err = arr[i].Value(), error(nil)
if err != nil {
return nil, fmt.Errorf("item %d: %w", i, err)
}
}
return res, nil
} (arr[index])
e.S, err = itemToUnnamed(arr[index], nil)
if err != nil {
return fmt.Errorf("field S: %w", err)
}

View file

@ -386,10 +386,12 @@ func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.Exte
over.TypeName = "map[" + t.Key().String() + "]" + over.TypeName
return smartcontract.MapType, stackitem.MapT, over, et
case *types.Struct:
var extName string
if isNamed {
over.Package = named.Obj().Pkg().Path()
over.TypeName = named.Obj().Pkg().Name() + "." + named.Obj().Name()
_ = c.genStructExtended(t, over.TypeName, exts)
extName = over.TypeName
} else {
name := "unnamed"
if exts != nil {
@ -398,11 +400,14 @@ func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.Exte
}
_ = c.genStructExtended(t, name, exts)
}
// For bindings configurator this structure becomes named in fact. Its name
// is "unnamed[X...X]".
extName = name
}
return smartcontract.ArrayType, stackitem.StructT, over,
&binding.ExtendedType{ // Value-less, refer to exts.
Base: smartcontract.ArrayType,
Name: over.TypeName,
Name: extName,
}
case *types.Slice: