diff --git a/edb/edgeql/compiler/func.py b/edb/edgeql/compiler/func.py index 1bb1294a60d..9041f22320b 100644 --- a/edb/edgeql/compiler/func.py +++ b/edb/edgeql/compiler/func.py @@ -41,6 +41,7 @@ from edb.common.typeutils import not_none from edb.ir import ast as irast +from edb.ir import staeval from edb.ir import utils as irutils from edb.schema import constraints as s_constr @@ -1043,17 +1044,18 @@ def compile_fts_with_options( assert lang_ty lang_domain = set() # languages that the fts index needs to support - if irutils.is_const(lang): + try: + lang_const = staeval.evaluate_to_python_val(lang, ctx.env.schema) + except staeval.UnsupportedExpressionError: + lang_const = None + + if lang_const is not None: # language is constant # -> determine its only value at compile time - lang_const = irutils.as_const(lang) - assert lang_const - lang_domain.add(str(lang_const.value).lower()) - + lang_domain.add(lang_const.lower()) else: # language is not constant # -> use all possible values of the enum - enum_values = lang_ty.get_enum_values(ctx.env.schema) assert enum_values for enum_value in enum_values: @@ -1061,17 +1063,14 @@ def compile_fts_with_options( # weight_category weight_expr = call.args['weight_category'].expr - if not irutils.is_const(weight_expr): + try: + weight: str = staeval.evaluate_to_python_val( + weight_expr, ctx.env.schema) + except staeval.UnsupportedExpressionError: raise errors.InvalidValueError( f"fts::search weight_category must be a constant", span=weight_expr.span, - ) - weight_const = irutils.as_const(weight_expr) - if weight_const: - weight = str(weight_const.value) - else: - weight = None - assert weight + ) from None return irast.FTSDocument( text=call.args[0].expr, diff --git a/edb/ir/utils.py b/edb/ir/utils.py index 8e102821d7c..f253bd2fb8f 100644 --- a/edb/ir/utils.py +++ b/edb/ir/utils.py @@ -498,17 +498,6 @@ def flt(n: irast.Call) -> bool: return bool(ast.find_children(ir, irast.Call, flt, terminate_early=True)) -def as_const(ir: irast.Base) -> Optional[irast.BaseConstant]: - match ir: - case irast.BaseConstant(): - return ir - case irast.TypeCast(): - return as_const(ir.expr) - case irast.SetE() if ir.expr: - return as_const(ir.expr) - return None - - T = TypeVar('T') diff --git a/tests/test_edgeql_fts_schema.py b/tests/test_edgeql_fts_schema.py index b3dcf107004..38cb54b0dd4 100644 --- a/tests/test_edgeql_fts_schema.py +++ b/tests/test_edgeql_fts_schema.py @@ -555,3 +555,39 @@ async def test_edgeql_fts_schema_weight_03(self): {"a": "hello world", "b": "running fox"}, ], ) + + async def test_edgeql_fts_schema_fiddly_args_01(self): + await self.con.execute( + r''' + create type Doc { + create required property x -> str; + create index fts::index on ( + fts::with_options( + .x, + language := ('en'++'g'), + weight_category := (select fts::Weight.B), + ) + ); + }; + ''' + ) + + async def test_edgeql_fts_schema_fiddly_args_02(self): + async with self.assertRaisesRegexTx( + edgedb.InvalidValueError, + "fts::search weight_category must be a constant", + ): + await self.con.execute( + r''' + create type Doc { + create required property x -> str; + create index fts::index on ( + fts::with_options( + .x, + language := fts::Language.eng, + weight_category := ("AB"[0]), + ) + ); + }; + ''' + )