Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array with external size #181

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 0.1.5 (Unreleased)

- fix: Array of fixed size of bytes with size in external package [GH-181](https://github.com/ferranbt/fastssz/pull/181)

# 0.1.4 (7 Aug, 2024)

- fix: Do not skip intermediate hashes in multi-proof [GH-173](https://github.com/ferranbt/fastssz/issues/173)]
Expand Down
12 changes: 12 additions & 0 deletions sszgen/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,18 @@ func (e *env) parseASTFieldType(name, tags string, expr ast.Expr) (*Value, error
return nil, fmt.Errorf("alias ref not found: %s", obj.Name)
}
astSize = &num
case *ast.SelectorExpr:
// TODO: this does not take into account the package name.
// If there are two exported const with the same name it is going to collide.
sel := obj.Sel.Name

num, ok := e.resolveAlias(sel)
if !ok {
return nil, fmt.Errorf("alias ref not found: %s", sel)
}
astSize = &num
default:
return nil, fmt.Errorf("unsupported array length type %T", obj)
}
}
if astSize != nil {
Expand Down
10 changes: 10 additions & 0 deletions sszgen/testcases/issue_164.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package testcases

import "github.com/ferranbt/fastssz/sszgen/testcases/other2"

//go:generate go run ../main.go --path issue_164.go --include ./other2

type Issue64 struct {
// Encoding generated will be for slice and not array
FeeRecipientAddress [other2.Size]byte
}
64 changes: 64 additions & 0 deletions sszgen/testcases/issue_164_encoding.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sszgen/testcases/other2/case4.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package other2

type Case4Slot uint64

const Size = 120
Loading