checkReturn checks the number of remaining overloaded function implementations. Returns ok=true if we should stop overload resolution, and returning either 1. the chosen overload in a slice, or 2. nil, along with the typed arguments. This modifies values within s as scratch slices, but only in the c
( ctx *SemaContext, s *typeCheckOverloadState, )
| 806 | // it returns true, which signals to the calling function that it should |
| 807 | // immediately return, so any mutations to s are irrelevant. |
| 808 | func checkReturn( |
| 809 | ctx *SemaContext, s *typeCheckOverloadState, |
| 810 | ) (ok bool, _ []TypedExpr, _ []overloadImpl, _ error) { |
| 811 | switch len(s.overloadIdxs) { |
| 812 | case 0: |
| 813 | if err := defaultTypeCheck(ctx, s, false); err != nil { |
| 814 | return false, nil, nil, err |
| 815 | } |
| 816 | return true, s.typedExprs, nil, nil |
| 817 | |
| 818 | case 1: |
| 819 | idx := s.overloadIdxs[0] |
| 820 | o := s.overloads[idx] |
| 821 | p := o.params() |
| 822 | for _, i := range s.constIdxs { |
| 823 | des := p.GetAt(i) |
| 824 | typ, err := s.exprs[i].TypeCheck(ctx, des) |
| 825 | if err != nil { |
| 826 | return false, s.typedExprs, nil, pgerror.Wrapf( |
| 827 | err, pgcode.InvalidParameterValue, |
| 828 | "error type checking constant value", |
| 829 | ) |
| 830 | } |
| 831 | if des != nil && !typ.ResolvedType().Equivalent(des) { |
| 832 | //return false, nil, nil, errors.AssertionFailedf( |
| 833 | // "desired constant value type %s but set type %s", |
| 834 | // log.Safe(des), log.Safe(typ.ResolvedType()), |
| 835 | //) |
| 836 | return false, nil, nil, errors.AssertionFailedf( |
| 837 | "desired constant value type %s but set type %s", |
| 838 | des, typ.ResolvedType(), |
| 839 | ) |
| 840 | } |
| 841 | s.typedExprs[i] = typ |
| 842 | } |
| 843 | |
| 844 | for _, i := range s.placeholderIdxs { |
| 845 | des := p.GetAt(i) |
| 846 | typ, err := s.exprs[i].TypeCheck(ctx, des) |
| 847 | if err != nil { |
| 848 | if des.IsAmbiguous() { |
| 849 | return false, nil, nil, nil |
| 850 | } |
| 851 | return false, nil, nil, err |
| 852 | } |
| 853 | s.typedExprs[i] = typ |
| 854 | } |
| 855 | return true, s.typedExprs, s.overloads[idx : idx+1], nil |
| 856 | |
| 857 | default: |
| 858 | return false, nil, nil, nil |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | func formatCandidates(prefix string, candidates []overloadImpl) string { |
| 863 | var buf bytes.Buffer |
no test coverage detected
searching dependent graphs…