Skip to content

Commit

Permalink
Fix array with external size
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Nov 6, 2024
1 parent 455b54c commit 2c7bb7f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
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

0 comments on commit 2c7bb7f

Please sign in to comment.