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 missing import for external []byte alias #167

Merged
merged 2 commits into from
Jun 28, 2024
Merged
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
10 changes: 3 additions & 7 deletions sszgen/generator/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@ func (v *Value) unmarshal(dst string) string {
validate = fmt.Sprintf("if len(%s) > %d { return ssz.ErrBytesLength }\n", dst, v.m)
}

refName := ""
if v.ref != "" {
refName = v.ref + "." + v.obj
}

// both fixed and dynamic are decoded equally
tmpl := `{{.validate}}if cap(::.{{.name}}) == 0 {
{{if .refName}} ::.{{.name}} = {{ .refName }}(make([]byte, 0, len({{.dst}}))) {{ else }} ::.{{.name}} = make([]byte, 0, len({{.dst}})) {{ end }}
{{if .isRef}} ::.{{.name}} = {{ ref .obj }}(make([]byte, 0, len({{.dst}}))) {{ else }} ::.{{.name}} = make([]byte, 0, len({{.dst}})) {{ end }}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was here, you have to use the new ref function during the template to record the values that need to be imported.

}
::.{{.name}} = append(::.{{.name}}, {{.dst}}...)`
return execTmpl(tmpl, map[string]interface{}{
"validate": validate,
"name": v.name,
"dst": dst,
"size": v.m,
"refName": refName,
"isRef": v.ref != "",
"obj": v,
})

case TypeUint:
Expand Down
9 changes: 9 additions & 0 deletions sszgen/testcases/issue_166.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package testcases

//go:generate go run ../main.go --path issue_165.go --include ./other

Check failure on line 3 in sszgen/testcases/issue_166.go

View workflow job for this annotation

GitHub Actions / Go test

running "go": exit status 1

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

type Issue165 struct {
A other.Case4Bytes
}
106 changes: 106 additions & 0 deletions sszgen/testcases/issue_166_encoding.go

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

Loading