MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / FindBinaryOverload

Function FindBinaryOverload

pkg/sql/sem/tree/typing.go:28–51  ·  view source on GitHub ↗

FindBinaryOverload finds the correct type signature overload for the specified binary operator, given the types of its inputs. If an overload is found, FindBinaryOverload returns true, plus a pointer to the overload. If an overload is not found, FindBinaryOverload returns false.

(
	bin treebin.BinaryOperatorSymbol, leftType, rightType *types.T,
)

Source from the content-addressed store, hash-verified

26// found, FindBinaryOverload returns true, plus a pointer to the overload.
27// If an overload is not found, FindBinaryOverload returns false.
28func FindBinaryOverload(
29 bin treebin.BinaryOperatorSymbol, leftType, rightType *types.T,
30) (ret *BinOp, ok bool) {
31
32 // Find the binary op that matches the type of the expression's left and
33 // right children. No more than one match should ever be found. The
34 // TestTypingBinaryAssumptions test ensures this will be the case even if
35 // new operators or overloads are added.
36 _ = BinOps[bin].ForEachBinOp(func(o *BinOp) error {
37 if leftType.Family() == types.UnknownFamily {
38 ok = rightType.Equivalent(o.RightType)
39 } else if rightType.Family() == types.UnknownFamily {
40 ok = leftType.Equivalent(o.LeftType)
41 } else {
42 ok = leftType.Equivalent(o.LeftType) && rightType.Equivalent(o.RightType)
43 }
44 if !ok {
45 return nil
46 }
47 ret = o
48 return iterutil.StopIteration()
49 })
50 return ret, ok
51}

Callers 1

InferBinaryTypeFunction · 0.85

Calls 4

StopIterationFunction · 0.92
ForEachBinOpMethod · 0.80
FamilyMethod · 0.80
EquivalentMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…