Skip to content

Commit

Permalink
[i-love-flamingo#7]: comparing struct after injection with empty struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Baumbusch committed Oct 25, 2022
1 parent 5db30fc commit f093326
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dingo.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,21 @@ func (injector *Injector) createInstanceOfAnnotatedType(t reflect.Type, annotati
subCircularTrace = append(subCircularTrace, circularTraceEntry{t, annotation})

n := reflect.New(t)
return n, injector.requestInjection(n.Interface(), subCircularTrace)
nInt := n.Interface()
err := injector.requestInjection(n.Interface(), subCircularTrace)
if reflect.DeepEqual(nInt, reflect.New(t).Interface()) {
return n, fmt.Errorf("element empty after injection. Might be caused by usage of struct instead of pointer receiver")
}
return n, err
}

n := reflect.New(t)
return n, injector.requestInjection(n.Interface(), nil)
nInt := n.Interface()
err := injector.requestInjection(nInt, nil)
if reflect.DeepEqual(nInt, reflect.New(t).Interface()) {
return n, fmt.Errorf("element empty after injection. Might be caused by usage of struct instead of pointer receiver")
}
return n, err
}

func reflectedError(err *error, t reflect.Type) reflect.Value {
Expand Down

2 comments on commit f093326

@tessig
Copy link

@tessig tessig commented on f093326 Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tristanessquare, thanks again for the nice discussion yesterday.
Feel free to provide this branch as pull request 🙂

@tristanexsquare
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tessig , well the test is correct, but the provided fix does not work yet.
There might be ChildStructs for which it is valid to be empty.

Nonetheless I can create a PR an continue working on it.

Please sign in to comment.