MCPcopy
hub / github.com/purpleidea/mgmt / Type

Method Type

lang/ast/structs.go:10804–10873  ·  view source on GitHub ↗

Type returns the type of this expression, which is the return type of the function call.

()

Source from the content-addressed store, hash-verified

10802// Type returns the type of this expression, which is the return type of the
10803// function call.
10804func (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 {

Callers 2

getPartialsMethod · 0.95
TestUnification1Function · 0.95

Calls 5

StringMethod · 0.95
WrapfFunction · 0.92
HasVariantMethod · 0.80
TypeMethod · 0.65
InfoMethod · 0.65

Tested by 1

TestUnification1Function · 0.76