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
The following code compiles, and will panic in a confusing way:
proto := bindnode.Prototype(schemaType, nil)
The right way to supply a schema type and infer the Go type is:
proto := bindnode.Prototype(nil, schemaType)
The Go type is passed as a ptrType interface{}, causing this footgun. Messing up the other way, e.g. proto := bindnode.Prototype(nil, (*MyType)(nil)) wouldn't compile, because the second parameter expects a schema.Type interface.
We can avoid this footgun by making the bindnode APIs panic if their "Go type" parameter implements the schema.Type interface. I don't see why anyone would ever implement it on purpose for a Go type used to back a bindnode node. The most likely explanation is that they got the order of the parameters wrong, like I just did.
The text was updated successfully, but these errors were encountered:
The following code compiles, and will panic in a confusing way:
The right way to supply a schema type and infer the Go type is:
The Go type is passed as a
ptrType interface{}
, causing this footgun. Messing up the other way, e.g.proto := bindnode.Prototype(nil, (*MyType)(nil))
wouldn't compile, because the second parameter expects aschema.Type
interface.We can avoid this footgun by making the bindnode APIs panic if their "Go type" parameter implements the
schema.Type
interface. I don't see why anyone would ever implement it on purpose for a Go type used to back a bindnode node. The most likely explanation is that they got the order of the parameters wrong, like I just did.The text was updated successfully, but these errors were encountered: