You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Invalid struct parsing after anonymous struct field
Description
When you create a structure, then you define an anonymous field and try to create a variable out of it, the parsing fails and it says "the variable after your anonymous field does not exist", like for example:
this is what i found tho, it does skip somewhere in the GetPathForName, see bellow
// gnovm/pkg/gnolang/preprocess.go:986case*StructType:
n.Path=bt.GetPathForName(n.Name) // here, bt.Fields have all the fields !returnn, TRANS_CONTINUE
i checked doing that:
case*StructType:
println("fields in structure:")
for_, v:=rangebt.Fields {
println("-", v.String())
}
println("field to check for:")
println(n.Name, "\n")
n.Path=bt.GetPathForName(n.Name)
// Outputs:// fields in structure:// - Anon struct{Value int}// - Hello int// field to check for:// Hello
so it is included well in the parsing, but the error is just bellow here:
// gnovm/pkg/gnolang/types.go:785func (st*StructType) GetPathForName(nName) ValuePath {
fori:=0; i<len(st.Fields); i++ { // it itters through the fieldsft:=st.Fields[i]
ifft.Name==n {
ifi>2<<16-1 {
panic("too many fields")
}
returnNewValuePathField(0, uint16(i), n)
}
ifst, ok:=ft.Type.(*StructType); ok { // if its anon struct it just skips... the number of fields IN the anon struct... but skips them in the parent struct ? why ?ifft.Name!="" {
// skip fields not promoted. (this comment is not from me, its from the code)i+=len(st.Fields)
}
}
}
panic(fmt.Sprintf("struct type %s has no field %s",
st.String(), n))
}
so for me the fix would be to get rid of the condition like that:
func (st *StructType) GetPathForName(n Name) ValuePath {
for i := 0; i < len(st.Fields); i++ {
ft := st.Fields[i]
if ft.Name == n {
if i > 2<<16-1 {
panic("too many fields")
}
return NewValuePathField(0, uint16(i), n)
}
- if st, ok := ft.Type.(*StructType); ok {- if ft.Name != "" {- // skip fields not promoted.- i += len(st.Fields)- }- }
}
panic(fmt.Sprintf("struct type %s has no field %s",
st.String(), n))
}
but this may be really usefull for something else, but i dont see why tho... ?
Note
removing the condition make the code works, but idk if it break everything
TL;DR
there is a condition when checking fields that just skips the fields in anon structure in gnovm/pkg/gnolang/types.go:794 and it seems useless, but im too scared to remove it because maybe it will break everything
The text was updated successfully, but these errors were encountered:
It seems buggy — you can probably just remove it. Then run make test in gnovm/Makefile, (maybe also examples/Makefile, gno.land/Makefile) to verify that everything still works.
Invalid struct parsing after anonymous struct field
Description
When you create a structure, then you define an anonymous field and try to create a variable out of it, the parsing fails and it says "the variable after your anonymous field does not exist", like for example:
will say:
(the full example bellow)
Your environment
go version go1.24.1 linux/amd64
gno version: master.2244+84e53f51
Steps to reproduce
Here is a code snippet
Expected behaviour
using golang:
Actual behaviour
using gno
Logs
here are the full logs after
gno run a.go
command:Proposed solution
ig its just a parsing typo somewhere in the code
this is what i found tho, it does skip somewhere in the GetPathForName, see bellow
i checked doing that:
so it is included well in the parsing, but the error is just bellow here:
so for me the fix would be to get rid of the condition like that:
but this may be really usefull for something else, but i dont see why tho... ?
Note
removing the condition make the code works, but idk if it break everything
TL;DR
there is a condition when checking fields that just skips the fields in anon structure in
gnovm/pkg/gnolang/types.go:794
and it seems useless, but im too scared to remove it because maybe it will break everythingThe text was updated successfully, but these errors were encountered: