fastssz icon indicating copy to clipboard operation
fastssz copied to clipboard

Const sized byte array fail to generate

Open karalabe opened this issue 1 year ago • 4 comments

This is fine:

type Address [20]byte

This blows up with byte array definition not understood by go/ast

const AddressLength = 20
type Address [AddressLength]byte

karalabe avatar Jun 27 '24 16:06 karalabe

Do you have a repro of the issue? It does work for me here.

ferranbt avatar Jun 28 '24 14:06 ferranbt

@ferranbt I'm encountering a different flavor of the issue @karalabe described above,

in your example you are defining the 3 - array size constant Issue164ElemSize, type Issue164Elem, struct Issue164 - all in the same package

if I try to use a constant from different (external) package - corresponds to Issue164ElemSize from your example - generator does produce _encoding.go file for me without errors, but the issue is it treats my array as slice (not constant size array!) - obviously failing to compile unless I adjust it manually.

Potentially somewhat related to https://github.com/ferranbt/fastssz/issues/179

iurii-ssv avatar Nov 03 '24 12:11 iurii-ssv

Can you share a small repro of the issue?

ferranbt avatar Nov 04 '24 09:11 ferranbt

What's also curious is that latest version seems to be 0.1.3 while 0.1.4 seems to have been out for a while now as per https://github.com/ferranbt/fastssz/tags

➜ go install github.com/ferranbt/fastssz/sszgen@latest
...
➜ sszgen version
0.1.3

Simple example, github.com/attestantio/go-eth2-client/spec/bellatrix I'm using is just an arbitrary external package:

package storage

import "github.com/attestantio/go-eth2-client/spec/bellatrix"

//go:generate sszgen -path ./shares.go --objs storageShare

type storageShare struct {
	// Encoding generated will be for slice and not array
	FeeRecipientAddress [bellatrix.ExecutionAddressLength]byte
}

iurii-ssv avatar Nov 04 '24 10:11 iurii-ssv