Type returns the type of this expression, which is the return type of the function call.
()
| 10802 | // Type returns the type of this expression, which is the return type of the |
| 10803 | // function call. |
| 10804 | func (obj *ExprCall) Type() (*types.Type, error) { |
| 10805 | |
| 10806 | // XXX: If we have the function statically in obj.Anon, run this? |
| 10807 | |
| 10808 | if obj.expr == nil { |
| 10809 | // possible programming error |
| 10810 | return nil, fmt.Errorf("call doesn't contain an expr pointer yet") |
| 10811 | } |
| 10812 | |
| 10813 | // function specific code follows... |
| 10814 | exprFunc, isFn := obj.expr.(*ExprFunc) |
| 10815 | if !isFn { |
| 10816 | if obj.typ == nil { |
| 10817 | return nil, errwrap.Wrapf(interfaces.ErrTypeCurrentlyUnknown, "%s", obj.String()) |
| 10818 | } |
| 10819 | return obj.typ, nil |
| 10820 | } |
| 10821 | |
| 10822 | sig, err := exprFunc.Type() |
| 10823 | if err != nil { |
| 10824 | return nil, err |
| 10825 | } |
| 10826 | if typ := sig.Out; typ != nil && !typ.HasVariant() && obj.typ == nil { |
| 10827 | return typ, nil // speculate! |
| 10828 | } |
| 10829 | |
| 10830 | // speculate if a partial return type is known |
| 10831 | if exprFunc.Body != nil { |
| 10832 | if exprFunc.Return != nil && obj.typ == nil { |
| 10833 | return exprFunc.Return, nil |
| 10834 | } |
| 10835 | |
| 10836 | if typ, err := exprFunc.Body.Type(); err == nil && obj.typ == nil { |
| 10837 | return typ, nil |
| 10838 | } |
| 10839 | } |
| 10840 | |
| 10841 | if exprFunc.Function != nil { |
| 10842 | // is it buildable? (formerly statically polymorphic) |
| 10843 | _, isBuildable := exprFunc.function.(interfaces.BuildableFunc) |
| 10844 | if !isBuildable && obj.typ == nil { |
| 10845 | if info := exprFunc.function.Info(); info != nil { |
| 10846 | if sig := info.Sig; sig != nil { |
| 10847 | if typ := sig.Out; typ != nil && !typ.HasVariant() { |
| 10848 | return typ, nil // speculate! |
| 10849 | } |
| 10850 | } |
| 10851 | } |
| 10852 | } |
| 10853 | // TODO: we could also check if a truly polymorphic type has |
| 10854 | // consistent return values across all possibilities available |
| 10855 | } |
| 10856 | |
| 10857 | //if len(exprFunc.Values) > 0 |
| 10858 | // check to see if we have a unique return type |
| 10859 | for _, fn := range exprFunc.Values { |
| 10860 | typ := fn.Type() |
| 10861 | if typ == nil || typ.Out == nil { |