Skip to content

node/bindnode: panic if a schema.Type is passed as a Go ptrType #382

Open
@mvdan

Description

@mvdan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low: Not priority right nowgood first issueGood issue for new contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions