Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error reporting for incorrect use of slice. #1420

Merged
merged 1 commit into from May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions edb/edgeql/compiler/inference/types.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
37 changes: 37 additions & 0 deletions tests/test_edgeql_expressions.py
Expand Up @@ -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];
""")