checks and returns a non-nil error if the target function: - returns an fx.Out struct as a result and has either a ResultTags or an As annotation - takes in an fx.In struct as a parameter and has either a ParamTags or a From annotation - has an error result not as the last result.
()
| 1756 | // - takes in an fx.In struct as a parameter and has either a ParamTags or a From annotation |
| 1757 | // - has an error result not as the last result. |
| 1758 | func (ann *annotated) typeCheckOrigFn() error { |
| 1759 | ft := reflect.TypeOf(ann.Target) |
| 1760 | numOut := ft.NumOut() |
| 1761 | for i := 0; i < numOut; i++ { |
| 1762 | ot := ft.Out(i) |
| 1763 | if ot == _typeOfError && i != numOut-1 { |
| 1764 | return fmt.Errorf( |
| 1765 | "only the last result can be an error: "+ |
| 1766 | "%v (%v) returns error as result %d", |
| 1767 | fxreflect.FuncName(ann.Target), ft, i) |
| 1768 | } |
| 1769 | if ot.Kind() != reflect.Struct { |
| 1770 | continue |
| 1771 | } |
| 1772 | if !dig.IsOut(reflect.New(ft.Out(i)).Elem().Interface()) { |
| 1773 | continue |
| 1774 | } |
| 1775 | if len(ann.ResultTags) > 0 || len(ann.As) > 0 { |
| 1776 | return errors.New("fx.Out structs cannot be annotated with fx.ResultTags or fx.As") |
| 1777 | } |
| 1778 | } |
| 1779 | for i := 0; i < ft.NumIn(); i++ { |
| 1780 | it := ft.In(i) |
| 1781 | if it.Kind() != reflect.Struct { |
| 1782 | continue |
| 1783 | } |
| 1784 | if !dig.IsIn(reflect.New(ft.In(i)).Elem().Interface()) { |
| 1785 | continue |
| 1786 | } |
| 1787 | if len(ann.ParamTags) > 0 || len(ann.From) > 0 { |
| 1788 | return errors.New("fx.In structs cannot be annotated with fx.ParamTags or fx.From") |
| 1789 | } |
| 1790 | } |
| 1791 | return nil |
| 1792 | } |
| 1793 | |
| 1794 | func (ann *annotated) currentResultTypes() (resultTypes []reflect.Type, hasError bool) { |
| 1795 | ft := reflect.TypeOf(ann.Target) |