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, )
| 26 | // found, FindBinaryOverload returns true, plus a pointer to the overload. |
| 27 | // If an overload is not found, FindBinaryOverload returns false. |
| 28 | func 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 | } |
no test coverage detected
searching dependent graphs…