Struct embedding works like this:
type ActionNode struct {
basicNode
}
Turns into:
type ActionNode struct {
basicNode basicNode
}
func (a *ActionNode) OutputsTo(n2 node) {
a.basicNode.OutputsTo(n2)
}
So basicNode will behave as a field of ActionNode with wrapper functions.
If you must embed and get basicNode out of a interface then you need to add
to your interface a new method to get basicNode,
e.g. https://play.golang.org/p/QhTmqeg9vgU
On Wednesday, 2 May 2018 03:43:17 UTC+8, Mark Nahabedian wrote:
>
> I don't know why I'm getting this interface conversion error or what to do
> about it.
>
> I define an interface, node, and a struct, basicNode that implements
> behavior common to all nodes. I also define ActionNode and TestNode which
> both anonymously embed basicNode.
>
> basicNode implements OutputsTo which links the receiver with the node
> passed as argument.
>
> I get the runtime error
>
> panic: interface conversion: main.node is *main.ActionNode, not
> *main.basicNode
>
>
>
>
> Here's a playground link that exhibits my problem:
>
> https://play.golang.org/p/ZeIkJSd7qB0
>
> Thanks.
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.