Skip to content

Commit

Permalink
Fix the panic caused by the closure bean
Browse files Browse the repository at this point in the history
  • Loading branch information
limpo1989 committed Nov 15, 2023
1 parent 7b8589c commit 729eb32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
32 changes: 17 additions & 15 deletions gs/gs.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,23 +489,25 @@ func (c *container) resolveBean(b *BeanDefinition) error {
if b.method {
selector, ok := b.f.Arg(0)
if !ok || selector == "" {
selector, _ = b.f.In(0)
selector, ok = b.f.In(0)
}
parents, err := c.findBean(selector)
if err != nil {
return err
}
n := len(parents)
if n > 1 {
msg := fmt.Sprintf("found %d parent beans, bean:%q type:%q [", n, selector, b.t.In(0))
for _, b := range parents {
msg += "( " + b.String() + " ), "
if ok {
parents, err := c.findBean(selector)
if err != nil {
return err
}

Check warning on line 498 in gs/gs.go

View check run for this annotation

Codecov / codecov/patch

gs/gs.go#L497-L498

Added lines #L497 - L498 were not covered by tests
n := len(parents)
if n > 1 {
msg := fmt.Sprintf("found %d parent beans, bean:%q type:%q [", n, selector, b.t.In(0))
for _, b := range parents {
msg += "( " + b.String() + " ), "
}
msg = msg[:len(msg)-2] + "]"
return errors.New(msg)

Check warning on line 506 in gs/gs.go

View check run for this annotation

Codecov / codecov/patch

gs/gs.go#L501-L506

Added lines #L501 - L506 were not covered by tests
} else if n == 0 {
b.status = Deleted
return nil
}
msg = msg[:len(msg)-2] + "]"
return errors.New(msg)
} else if n == 0 {
b.status = Deleted
return nil
}
}

Expand Down
6 changes: 5 additions & 1 deletion gs/gs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3070,10 +3070,14 @@ func (tac *testAutoConfiguration) NewEmpty() *BeanDefinition {
return NewBean(new(struct{})).Name("empty")
}

func (tac *testAutoConfiguration) NewFoo() *testFoo {
func (tac *testAutoConfiguration) newFoo() *testFoo {
return &testFoo{prefix: tac.Prefix}
}

func (tac *testAutoConfiguration) NewFoo() *BeanDefinition {
return NewBean(tac.newFoo)
}

func (tac *testAutoConfiguration) NewBar(foo *testFoo) (*testBar, error) {
return &testBar{foo: foo}, nil
}
Expand Down

0 comments on commit 729eb32

Please sign in to comment.