MCPcopy Create free account
hub / github.com/dolthub/doltgresql / TypeCheck

Method TypeCheck

postgres/parser/sem/tree/type_check.go:1251–1298  ·  view source on GitHub ↗

TypeCheck implements the Expr interface.

(
	ctx context.Context, semaCtx *SemaContext, desired *types.T,
)

Source from the content-addressed store, hash-verified

1249
1250// TypeCheck implements the Expr interface.
1251func (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.
1301func (expr DefaultVal) TypeCheck(

Callers

nothing calls this directly

Calls 9

NewfFunction · 0.92
WrapfFunction · 0.92
typeCheckOverloadedExprsFunction · 0.85
formatCandidatesFunction · 0.85
FamilyMethod · 0.80
checkVolatilityMethod · 0.80
ResolvedTypeMethod · 0.65
StringMethod · 0.65
returnTypeMethod · 0.65

Tested by

no test coverage detected