Skip to content

Commit

Permalink
fix: update Anonymous stauct
Browse files Browse the repository at this point in the history
  • Loading branch information
kooksee committed Dec 8, 2023
1 parent 8a5bbf5 commit 0708011
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 3 additions & 1 deletion example/struct-in/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

type a struct {
b
B b
}

Expand All @@ -29,7 +30,8 @@ func main() {
})

arg := di.Inject(new(a))
assert.If(arg.B.C.C != "hello", "not match")
assert.If(arg.C.C != "hello", "not match")
fmt.Println(arg.C.C)
fmt.Println(arg.B.C.C)
fmt.Println(di.Graph())

Expand Down
6 changes: 1 addition & 5 deletions internal/dix_inter/dix.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,8 @@ func (x *Dix) injectFunc(vp reflect.Value, opt Options) {
func (x *Dix) injectStruct(vp reflect.Value, opt Options) {
tp := vp.Type()
for i := 0; i < tp.NumField(); i++ {
if !vp.Field(i).CanSet() {
continue
}

field := tp.Field(i)
if field.Anonymous {
if !vp.Field(i).CanSet() && field.Type.Kind() != reflect.Struct {
continue
}

Expand Down

0 comments on commit 0708011

Please sign in to comment.