Skip to content

Commit 0708011

Browse files
committed
fix: update Anonymous stauct
1 parent 8a5bbf5 commit 0708011

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

example/struct-in/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type a struct {
13+
b
1314
B b
1415
}
1516

@@ -29,7 +30,8 @@ func main() {
2930
})
3031

3132
arg := di.Inject(new(a))
32-
assert.If(arg.B.C.C != "hello", "not match")
33+
assert.If(arg.C.C != "hello", "not match")
34+
fmt.Println(arg.C.C)
3335
fmt.Println(arg.B.C.C)
3436
fmt.Println(di.Graph())
3537

internal/dix_inter/dix.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,8 @@ func (x *Dix) injectFunc(vp reflect.Value, opt Options) {
296296
func (x *Dix) injectStruct(vp reflect.Value, opt Options) {
297297
tp := vp.Type()
298298
for i := 0; i < tp.NumField(); i++ {
299-
if !vp.Field(i).CanSet() {
300-
continue
301-
}
302-
303299
field := tp.Field(i)
304-
if field.Anonymous {
300+
if !vp.Field(i).CanSet() && field.Type.Kind() != reflect.Struct {
305301
continue
306302
}
307303

0 commit comments

Comments
 (0)