Repository: edgedb/edgedb

Issue:
Trying to slice wrong type produces InternalServerError (only right index)
EdgeDB version: `1.0-alpha.2+dev.505.g5b68ec24`

Steps to reproduce:
```
modbay_beta> SELECT 6[:1];                                                                                                                                                                                             
InternalServerError: 'NoneType' object has no attribute 'context'
```

Using left index or both slice indexes causes proper error message:
```
modbay_beta> SELECT 6[1:1];                                                                                                                                                                                            
QueryError: scalar type 'std::int64' cannot be sliced

modbay_beta> SELECT 6[1:];                                                                                                                                                                                             
QueryError: scalar type 'std::int64' cannot be sliced
```


Discussion:

Resolving patch:
diff --git a/edb/edgeql/compiler/inference/types.py b/edb/edgeql/compiler/inference/types.py
--- 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
 


Test patch:
diff --git a/tests/test_edgeql_expressions.py b/tests/test_edgeql_expressions.py
--- 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];
+            """)