I just posted this on on openstack.
Maybe someone here knows the answer?

https://stackoverflow.com/questions/55410250/go-passing-a-member-function-as-an-argument-compile-error

I would expect this to compile after watching this talk by Rob Pike 
https://www.youtube.com/watch?v=HxaD_trXwRE&t=1830s 


package main

type StateFunc func(*M) StateFunc

type M struct {
    start StateFunc
}

func New(start StateFunc) *M {
    return &M{
        start: start,
    }
}

func (m *M) foo() StateFunc {
    return nil
}

func (m *M) Start() {
    go m.run()
}

func (m *M) run() {
    state := m.start
    for state != nil {
        state = state(m)
    }
}

func main() {
    m := New(foo)
}


It fails with

prog.go:31:14: undefined: foo




-- 
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.

Reply via email to