forked from TrueCloudLab/neoneo-go
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:
parent
0195aae824
commit
6379bcc15a
2 changed files with 8 additions and 16 deletions
|
@ -95,7 +95,7 @@ type SomeMapEvent struct {
|
||||||
|
|
||||||
// SomeStructEvent represents "SomeStruct" event emitted by the contract.
|
// SomeStructEvent represents "SomeStruct" event emitted by the contract.
|
||||||
type SomeStructEvent struct {
|
type SomeStructEvent struct {
|
||||||
S []any
|
S *Unnamed
|
||||||
}
|
}
|
||||||
|
|
||||||
// SomeArrayEvent represents "SomeArray" event emitted by the contract.
|
// SomeArrayEvent represents "SomeArray" event emitted by the contract.
|
||||||
|
@ -1052,20 +1052,7 @@ func (e *SomeStructEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
index++
|
index++
|
||||||
e.S, err = func (item stackitem.Item) ([]any, error) {
|
e.S, err = itemToUnnamed(arr[index], nil)
|
||||||
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])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("field S: %w", err)
|
return fmt.Errorf("field S: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,10 +386,12 @@ func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.Exte
|
||||||
over.TypeName = "map[" + t.Key().String() + "]" + over.TypeName
|
over.TypeName = "map[" + t.Key().String() + "]" + over.TypeName
|
||||||
return smartcontract.MapType, stackitem.MapT, over, et
|
return smartcontract.MapType, stackitem.MapT, over, et
|
||||||
case *types.Struct:
|
case *types.Struct:
|
||||||
|
var extName string
|
||||||
if isNamed {
|
if isNamed {
|
||||||
over.Package = named.Obj().Pkg().Path()
|
over.Package = named.Obj().Pkg().Path()
|
||||||
over.TypeName = named.Obj().Pkg().Name() + "." + named.Obj().Name()
|
over.TypeName = named.Obj().Pkg().Name() + "." + named.Obj().Name()
|
||||||
_ = c.genStructExtended(t, over.TypeName, exts)
|
_ = c.genStructExtended(t, over.TypeName, exts)
|
||||||
|
extName = over.TypeName
|
||||||
} else {
|
} else {
|
||||||
name := "unnamed"
|
name := "unnamed"
|
||||||
if exts != nil {
|
if exts != nil {
|
||||||
|
@ -398,11 +400,14 @@ func (c *codegen) scAndVMTypeFromType(t types.Type, exts map[string]binding.Exte
|
||||||
}
|
}
|
||||||
_ = c.genStructExtended(t, name, exts)
|
_ = 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,
|
return smartcontract.ArrayType, stackitem.StructT, over,
|
||||||
&binding.ExtendedType{ // Value-less, refer to exts.
|
&binding.ExtendedType{ // Value-less, refer to exts.
|
||||||
Base: smartcontract.ArrayType,
|
Base: smartcontract.ArrayType,
|
||||||
Name: over.TypeName,
|
Name: extName,
|
||||||
}
|
}
|
||||||
|
|
||||||
case *types.Slice:
|
case *types.Slice:
|
||||||
|
|
Loading…
Reference in a new issue