diff --git a/edb/edgeql/compiler/inference/types.py b/edb/edgeql/compiler/inference/types.py index b106093b101..d1e7472a544 100644 --- a/edb/edgeql/compiler/inference/types.py +++ b/edb/edgeql/compiler/inference/types.py @@ -374,7 +374,7 @@ def __infer_slice( # the base type is not valid raise errors.QueryError( f'{node_type.get_verbosename(env.schema)} cannot be sliced', - context=ir.start.context) + context=ir.expr.context) for index in [ir.start, ir.stop]: if index is not None: @@ -463,7 +463,7 @@ def __infer_index( raise errors.QueryError( f'index indirection cannot be applied to ' f'{node_type.get_verbosename(env.schema)}', - context=ir.index.context) + context=ir.expr.context) return result diff --git a/tests/test_edgeql_expressions.py b/tests/test_edgeql_expressions.py index 32dcbea6144..325173d8f48 100644 --- a/tests/test_edgeql_expressions.py +++ b/tests/test_edgeql_expressions.py @@ -4498,3 +4498,40 @@ async def test_edgeql_expr_group_06(self): ''', [[1, 3], [2, 1], [3, 2]] ) + + async def test_edgeql_expr_slice_01(self): + with self.assertRaisesRegex( + edgedb.QueryError, + r"scalar type 'std::int64' cannot be sliced"): + + await self.con.execute(""" + SELECT 1[1:3]; + """) + + async def test_edgeql_expr_slice_02(self): + with self.assertRaisesRegex( + edgedb.QueryError, + r"scalar type 'std::int64' cannot be sliced"): + + await self.con.execute(""" + SELECT 1[:3]; + """) + + async def test_edgeql_expr_slice_03(self): + with self.assertRaisesRegex( + edgedb.QueryError, + r"scalar type 'std::int64' cannot be sliced"): + + await self.con.execute(""" + SELECT 1[1:]; + """) + + async def test_edgeql_expr_index_01(self): + with self.assertRaisesRegex( + edgedb.QueryError, + r"index indirection cannot be applied to scalar type " + r"'std::int64'"): + + await self.con.execute(""" + SELECT 1[1]; + """)