Skip to content

Commit 1044a94

Browse files
committed
sql/sem/tree: simplify SemaCtx reject flag checks
Release note: None
1 parent d057bda commit 1044a94

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pkg/sql/sem/tree/type_check.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func (expr *CastExpr) TypeCheck(
606606
castFrom := typedSubExpr.ResolvedType()
607607
allowStable := true
608608
context := ""
609-
if semaCtx != nil && semaCtx.Properties.required.rejectFlags&RejectStableOperators != 0 {
609+
if semaCtx != nil && semaCtx.Properties.IsSet(RejectStableOperators) {
610610
allowStable = false
611611
context = semaCtx.Properties.required.context
612612
}
@@ -962,12 +962,12 @@ func (sc *SemaContext) checkFunctionUsage(expr *FuncExpr, def *ResolvedFunctionD
962962
return err
963963
}
964964
if expr.IsWindowFunctionApplication() {
965-
if sc.Properties.required.rejectFlags&RejectWindowApplications != 0 {
965+
if sc.Properties.IsSet(RejectWindowApplications) {
966966
return NewInvalidFunctionUsageError(WindowClass, sc.Properties.required.context)
967967
}
968968

969969
if sc.Properties.Derived.InWindowFunc &&
970-
sc.Properties.required.rejectFlags&RejectNestedWindowFunctions != 0 {
970+
sc.Properties.IsSet(RejectNestedWindowFunctions) {
971971
return pgerror.Newf(pgcode.Windowing, "window function calls cannot be nested")
972972
}
973973
sc.Properties.Derived.SeenWindowApplication = true
@@ -976,21 +976,21 @@ func (sc *SemaContext) checkFunctionUsage(expr *FuncExpr, def *ResolvedFunctionD
976976
// we have an aggregation.
977977
if fnCls == AggregateClass {
978978
if sc.Properties.Derived.inFuncExpr &&
979-
sc.Properties.required.rejectFlags&RejectNestedAggregates != 0 {
979+
sc.Properties.IsSet(RejectNestedAggregates) {
980980
return NewAggInAggError()
981981
}
982-
if sc.Properties.required.rejectFlags&RejectAggregates != 0 {
982+
if sc.Properties.IsSet(RejectAggregates) {
983983
return NewInvalidFunctionUsageError(AggregateClass, sc.Properties.required.context)
984984
}
985985
sc.Properties.Derived.SeenAggregate = true
986986
}
987987
}
988988
if fnCls == GeneratorClass {
989989
if sc.Properties.Derived.inFuncExpr &&
990-
sc.Properties.required.rejectFlags&RejectNestedGenerators != 0 {
990+
sc.Properties.IsSet(RejectNestedGenerators) {
991991
return NewInvalidNestedSRFError(sc.Properties.required.context)
992992
}
993-
if sc.Properties.required.rejectFlags&RejectGenerators != 0 {
993+
if sc.Properties.IsSet(RejectGenerators) {
994994
return NewInvalidFunctionUsageError(GeneratorClass, sc.Properties.required.context)
995995
}
996996
sc.Properties.Derived.SeenGenerator = true
@@ -1023,15 +1023,15 @@ func (sc *SemaContext) checkVolatility(v volatility.V) error {
10231023
}
10241024
switch v {
10251025
case volatility.Volatile:
1026-
if sc.Properties.required.rejectFlags&RejectVolatileFunctions != 0 {
1026+
if sc.Properties.IsSet(RejectVolatileFunctions) {
10271027
// The code FeatureNotSupported is a bit misleading here,
10281028
// because we probably can't support the feature at all. However
10291029
// this error code matches PostgreSQL's in the same conditions.
10301030
return pgerror.Newf(pgcode.FeatureNotSupported,
10311031
"volatile functions are not allowed in %s", sc.Properties.required.context)
10321032
}
10331033
case volatility.Stable:
1034-
if sc.Properties.required.rejectFlags&RejectStableOperators != 0 {
1034+
if sc.Properties.IsSet(RejectStableOperators) {
10351035
return NewContextDependentOpsNotAllowedError(sc.Properties.required.context)
10361036
}
10371037
}
@@ -1529,7 +1529,7 @@ func (expr *RangeCond) TypeCheck(
15291529

15301530
// TypeCheck implements the Expr interface.
15311531
func (expr *Subquery) TypeCheck(_ context.Context, sc *SemaContext, _ *types.T) (TypedExpr, error) {
1532-
if sc != nil && sc.Properties.required.rejectFlags&RejectSubqueries != 0 {
1532+
if sc != nil && sc.Properties.IsSet(RejectSubqueries) {
15331533
return nil, pgerror.Newf(pgcode.FeatureNotSupported,
15341534
"subqueries are not allowed in %s", sc.Properties.required.context)
15351535
}

0 commit comments

Comments
 (0)