-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow fx.Annotate on In/Out structs with ResultTags/ParamTags, respectively #1053
Conversation
…tively. It is currently not possible for fx.Annotate to be used on a function that takes in or returns fx.In and fx.Out structs. This limitation, however, is not necessary when the annotation is different from the struct defined annotations, such as using fx.In with fx.ResultTags Annotation or fx.Out with fx.ParamTags Annotation. This loosens the constraint so that these Annotations become valid. Fixes uber-go#980.
Codecov Report
@@ Coverage Diff @@
## master #1053 +/- ##
=======================================
Coverage 98.52% 98.52%
=======================================
Files 39 39
Lines 2989 2989
=======================================
Hits 2945 2945
Misses 37 37
Partials 7 7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Should we update the "pre-requisites" section here: https://uber-go.github.io/fx/annotate.html#annotating-a-function ? |
Good call. updated. |
In #1053, we eased up the requirement for function signature for applying annotations to allow using In/Out structs with ResultTags/ParamTags. This had an unintended change in behavior where users are now able to use In/Out structs with From/As annotations. For example, the below code used to error out: > type Foo interface { ... } > type Bar struct { ... } // Bar implements Foo > struct Res { > fx.Out > > ABar Bar > } > fx.Annotate( > func() Res { ... }, > fx.As(new(Foo)), > ) Currently the code above applies the As annotation to ABar field and transforms the target function's signature accordingly. However, this was an unintended change in behavior, and we should have a design discussion about whether we actually want this before cutting a new release. Since it will require a breaking change to disable this after a new release is cut, I think the safe approach is to disable this for now and enable it after having decided that this is indeed what we want. Fixes #1060 --------- Co-authored-by: Sung Yoon Whang <sungyoonwhang@gmail.com> Co-authored-by: JacobOaks <jacoboaks.8@gmail.com>
It is currently not possible for fx.Annotate to be used on a function that takes in or returns fx.In and fx.Out structs.
This limitation, however, is not necessary when the annotation is different from the struct defined annotations, such as using fx.In with fx.ResultTags Annotation or fx.Out with fx.ParamTags Annotation.
This loosens the constraint so that these combinations of Annotations become valid.
Fixes #980.