> It just doesn't work anymore! Error message is "S1 does not implement
> Shower (Show method requires pointer receiver)".
Your example makes little sense from several angles, but the error is
accurate: S1 is not a Shower, but *S1 is. Pass &s1 to InvokeShow.
Dave.
type Shower interface {
Show()
}
type S1 struct {
}
func (this *S1) Show() {
println("Show from S1")
}
func InvokeShow(s Shower) {
if s1, ok := s.(S1); ok {
s1.Show()
}
}
func main() {
var s1 S1
InvokeShow(s1)
}
It just doesn't work anymore! Error message is "S1 does not implement
Shower (Show method requires pointer receiver)".
> I tested it, pass &s1 to InvokeShow, error message changes to
> "impossible type assertion: s (type Shower) cannot have dynamic type
> S1 (missing Show method)".
Again, the error message is telling you *exactly* what is wrong. You
are doing a type assertion of s to S1, and the compiler is saying that
that's impossible. You could change the type assertion to *S1, since
that is the type that you're passing around.
Dave.
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/-ZoCu5m0kJ4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Oh wow, my mind is blown. Is this due to some limitation of interface in translating values to points properly for pointer receivers?
Oh wow, my mind is blown. Is this due to some limitation of interface in translating values to points properly for pointer receivers?