Skip to content

Commit 650eac4

Browse files
craig[bot]mw5h
andcommitted
Merge #144975
144975: tree: don't match variadic builtins when arg list is too short r=yuzefovich a=mw5h The new processing for variadic builtins is pretty permissive in what it allows because they underlying implementations are pretty permissive in what they accept. However, fixed arguments are still fixed arguments and must match. Fixes: #144447 Release note: None Co-authored-by: Matt White <[email protected]>
2 parents df2b1b1 + 68611e0 commit 650eac4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/sql/logictest/testdata/logic_test/builtin_function

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,12 @@ Testing three, two, three
27182718
query error pq: format\(\): error parsing format string: not enough arguments
27192719
SELECT format(E'%2\x24s','foo');
27202720

2721+
statement error pgcode 42883 pq: unknown signature: format\(\)
2722+
SELECT format();
2723+
2724+
statement error pgcode 42883 pq: unknown signature: format\(int\)
2725+
SELECT format(42);
2726+
27212727
subtest pg_is_in_recovery
27222728

27232729
query B colnames

pkg/sql/sem/tree/overload.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,9 @@ func (s *overloadTypeChecker) typeCheckOverloadedExprs(
917917
// Process variadic functions with unrestrained wildcards as their variadic
918918
// parameter. This special cas short circuits the logic below, most of which
919919
// assumes AnyElement behavior for untyped parameters.
920+
//
921+
// TODO(mw5h): This is an ugly special case. Refactor this to use the logic
922+
// below. I'd do it now but it's a bit too high risk this close to 25.2.
920923
for i := range s.params {
921924
if vt, ok := s.params[i].(VariadicType); ok && vt.VarType == types.Any {
922925
if semaCtx.UsePre_25_2VariadicBuiltins {
@@ -926,16 +929,25 @@ func (s *overloadTypeChecker) typeCheckOverloadedExprs(
926929
if numOverloads > 1 {
927930
return errors.AssertionFailedf(
928931
"only one overload can have VariadicType {types.Any} parameters")
932+
} else if !vt.MatchLen(len(s.exprs)) {
933+
s.overloadIdxs = s.overloadIdxs[:0]
934+
return nil
929935
}
936+
typeCheckOk := true
930937
for j := range s.exprs {
931938
typedExpr, err := s.exprs[j].TypeCheck(ctx, semaCtx, vt.GetAt(j))
932939
if err != nil {
933940
return pgerror.Wrapf(err, pgcode.InvalidParameterValue,
934941
"error type checking resolved expression:")
942+
} else if !vt.MatchAt(typedExpr.ResolvedType(), j) {
943+
typeCheckOk = false
935944
}
936945
s.typedExprs[j] = typedExpr
937946
}
938-
s.overloadIdxs = append(s.overloadIdxs[:0], uint8(i))
947+
s.overloadIdxs = s.overloadIdxs[:0]
948+
if typeCheckOk {
949+
s.overloadIdxs = append(s.overloadIdxs, uint8(i))
950+
}
939951
return nil
940952
}
941953
}

0 commit comments

Comments
 (0)