TypeCheck implements the Expr interface.
( ctx context.Context, semaCtx *SemaContext, desired *types.T, )
| 1249 | |
| 1250 | // TypeCheck implements the Expr interface. |
| 1251 | func (expr *UnaryExpr) TypeCheck( |
| 1252 | ctx context.Context, semaCtx *SemaContext, desired *types.T, |
| 1253 | ) (TypedExpr, error) { |
| 1254 | ops := UnaryOps[expr.Operator] |
| 1255 | |
| 1256 | typedSubExprs, fns, err := typeCheckOverloadedExprs(ctx, semaCtx, desired, ops, false, expr.Expr) |
| 1257 | if err != nil { |
| 1258 | return nil, err |
| 1259 | } |
| 1260 | |
| 1261 | exprTyped := typedSubExprs[0] |
| 1262 | exprReturn := exprTyped.ResolvedType() |
| 1263 | |
| 1264 | // Return NULL if at least one overload is possible and NULL is an argument. |
| 1265 | if len(fns) > 0 { |
| 1266 | if exprReturn.Family() == types.UnknownFamily { |
| 1267 | return DNull, nil |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | // Throw a typing error if overload resolution found either no compatible candidates |
| 1272 | // or if it found an ambiguity. |
| 1273 | if len(fns) != 1 { |
| 1274 | var desStr string |
| 1275 | if desired.Family() != types.AnyFamily { |
| 1276 | desStr = fmt.Sprintf(" (desired <%s>)", desired) |
| 1277 | } |
| 1278 | sig := fmt.Sprintf("%s <%s>%s", expr.Operator, exprReturn, desStr) |
| 1279 | if len(fns) == 0 { |
| 1280 | return nil, |
| 1281 | pgerror.Newf(pgcode.InvalidParameterValue, unsupportedUnaryOpErrFmt, sig) |
| 1282 | } |
| 1283 | fnsStr := formatCandidates(expr.Operator.String(), fns) |
| 1284 | err = pgerror.Newf(pgcode.AmbiguousFunction, ambiguousUnaryOpErrFmt, sig) |
| 1285 | err = errors.WithHintf(err, candidatesHintFmt, fnsStr) |
| 1286 | return nil, err |
| 1287 | } |
| 1288 | |
| 1289 | unaryOp := fns[0].(*UnaryOp) |
| 1290 | if err := semaCtx.checkVolatility(unaryOp.Volatility); err != nil { |
| 1291 | return nil, pgerror.Wrapf(err, pgcode.InvalidParameterValue, "%s", expr.Operator) |
| 1292 | } |
| 1293 | |
| 1294 | expr.Expr = exprTyped |
| 1295 | expr.fn = unaryOp |
| 1296 | expr.typ = unaryOp.returnType()(typedSubExprs) |
| 1297 | return expr, nil |
| 1298 | } |
| 1299 | |
| 1300 | // TypeCheck implements the Expr interface. |
| 1301 | func (expr DefaultVal) TypeCheck( |
nothing calls this directly
no test coverage detected