Skip to content
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

Merged
merged 3 commits into from
Mar 10, 2023

Conversation

sywhang
Copy link
Contributor

@sywhang sywhang commented Mar 10, 2023

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.

…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
Copy link

codecov bot commented Mar 10, 2023

Codecov Report

Merging #1053 (83b9e0d) into master (7e9108b) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1053   +/-   ##
=======================================
  Coverage   98.52%   98.52%           
=======================================
  Files          39       39           
  Lines        2989     2989           
=======================================
  Hits         2945     2945           
  Misses         37       37           
  Partials        7        7           
Impacted Files Coverage Δ
annotated.go 99.23% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@JacobOaks
Copy link
Contributor

Should we update the "pre-requisites" section here: https://uber-go.github.io/fx/annotate.html#annotating-a-function ?

@sywhang
Copy link
Contributor Author

sywhang commented Mar 10, 2023

Should we update the "pre-requisites" section here: https://uber-go.github.io/fx/annotate.html#annotating-a-function ?

Good call. updated.

@sywhang sywhang merged commit 60031c6 into uber-go:master Mar 10, 2023
@sywhang sywhang deleted the 980 branch March 10, 2023 18:53
sywhang added a commit that referenced this pull request Apr 18, 2023
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Annotation: Param/ResultTags with In/Out
3 participants