Find the panic!
package main | |
import "fmt" | |
type BM struct { | |
d string | |
} | |
func NewBM() *BM { return &BM{d: "Hi",}} | |
type CM struct {} | |
func NewCM() *CM { return &CM{}} | |
type A struct { | |
bM *BM | |
cM *CM | |
} | |
func NewA() (*A, error) { | |
a := &A{} | |
bM, err := a.BM() | |
if err != nil { | |
return nil, err | |
} | |
a.bM = bM | |
cM, err := a.CM() | |
if err != nil { | |
return nil, err | |
} | |
a.cM = cM | |
return a, nil | |
} | |
func (this *A) BM() (*BM, error) { | |
if this.BM != nil { | |
fmt.Printf("Returning this.bM") | |
return this.bM, nil | |
} | |
return NewBM(), nil | |
} | |
func (this *A) CM() (*CM, error) { | |
if this.cM != nil { | |
fmt.Printf("Returning this.cM") | |
return this.cM, nil | |
} | |
bM, err := this.BM() | |
if err != nil { | |
return nil, err | |
} | |
fmt.Printf("%s", bM.d) | |
return NewCM(), nil | |
} | |
func main() { | |
_, err := NewA() | |
if err != nil { | |
fmt.Printf("%s", error.Error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment