> > That shows that basicNode's inputs and outputs fields are not visible as > fields of ActionNode or TestNode though.
Yup, struct embedding is just a shortcut to writing wrapper functions. Even if basicNode's fields gets promoted to ActionNode's fields, doing b2 := n2.(*basicNode) Wouldn't work anyway, they are still completely different named types and go is very strict on that. On Wednesday, 2 May 2018 05:21:51 UTC+8, Mark Nahabedian wrote: > > I was expecting that since basicNode is anonymously embedded into TestNode > and ActionNode, that the methods and fields of basicNode would all be > present in TestNode and ActionNode. In that case I'd have expected > > https://play.golang.org/p/gIvykcxFTmQ > > to have worked. That shows that basicNode's inputs and outputs fields are > not visible as fields of ActionNode or TestNode though. > > > > > On Tuesday, May 1, 2018 at 3:58:35 PM UTC-4, alex....@gmail.com wrote: >> >> 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 golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.