I've been playing with StructOf to build go values that match a serialized schema-driven form.
I've encountered an edge case that I'm uncertain whether Go currently supports. Given the struct:
typeSstruct {
Ptr*S
}
I see no way to forward-declare the S struct to use it as a pointer field to StructOf.
Is there some way I can build this struct type?
The text was updated successfully, but these errors were encountered:
bradfitz
changed the title
StructOf pointer field to itself
reflect: StructOf doesn't support recursive structs
Apr 17, 2017
s := reflect.StructOf(someFields) //want this to contain n but n doesn't exist yet
n := reflect.NamedOf(s, "S", nil)
but without a mechanism for forward declaration, as mentioned in the OP, how do you add a field to s of type n when the construction of n requires that s was already constructed?
(A related concern came up in #4146 where you would need n to define the signatures of the methods to add to n, but that's easier to handle).
go version: 1.8
I've been playing with
StructOf
to build go values that match a serialized schema-driven form.I've encountered an edge case that I'm uncertain whether Go currently supports. Given the struct:
I see no way to forward-declare the
S
struct to use it as a pointer field toStructOf
.Is there some way I can build this struct type?
The text was updated successfully, but these errors were encountered: