Repository: geldata/gel
Pull request: Disallow shapes on computed links
We currently produce nonsensical error messages saying a type does not
exist that clearly does.

Fixes #3369.

Problem statement:
InvalidReferenceError when creating an alias
<!-- Please search existing issues to avoid creating duplicates. -->
- EdgeDB Version: rc4 (current master)
- OS Version: linux

Steps to Reproduce:

```
edgedb> create type Foo;
OK: CREATE TYPE
edgedb> create type Bar;
OK: CREATE TYPE
edgedb> alter type Foo create link bar := Bar{val := 42};
error: InvalidReferenceError: object type 'default::Bar' does not exist
  ┌─ query:1:35
  │
1 │ alter type Foo create link bar := Bar{val := 42};
  │                                   ^^^^^^^^^^^^^^ error
```

Notice that this is achieved in DDL, so it doesn't look like a typical case of SDL ordering that prevents visibility.

Hints from issue discussion:

Commit message: Disallow shapes on computed links

We currently produce nonsensical error messages saying a type does not
exist that clearly does.

Fixes #3369.

Patch to review:
diff --git a/edb/schema/pointers.py b/edb/schema/pointers.py
index 9b6c0875068..6a5da23bfe5 100644
--- a/edb/schema/pointers.py
+++ b/edb/schema/pointers.py
@@ -1211,6 +1211,17 @@ def _parse_computable(
                     context=srcctx,
                 )
 
+        if (
+            not isinstance(source, Pointer)
+            and not source.is_view(schema)  # type: ignore
+            and target.is_view(expression.irast.schema)
+        ):
+            raise errors.UnsupportedFeatureError(
+                f'including a shape on schema-defined computed pointers '
+                f'is not yet supported',
+                context=self.source_context,
+            )
+
         spec_target: Optional[
             Union[
                 s_types.TypeShell[s_types.Type],
diff --git a/tests/test_edgeql_ddl.py b/tests/test_edgeql_ddl.py
index 34516515af7..a830e64816a 100644
--- a/tests/test_edgeql_ddl.py
+++ b/tests/test_edgeql_ddl.py
@@ -6517,6 +6517,22 @@ async def test_edgeql_ddl_link_computable_01(self):
             }],
         )
 
+    async def test_edgeql_ddl_link_computable_02(self):
+        await self.con.execute('''
+            CREATE TYPE LinkTarget;
+        ''')
+
+        # TODO We want to actually support this, but until then we should
+        # have a decent error.
+        async with self.assertRaisesRegexTx(
+            edgedb.UnsupportedFeatureError,
+            r"including a shape on schema-defined computed pointers "
+            r"is not yet supported"
+        ):
+            await self.con.execute("""
+                CREATE TYPE X { CREATE LINK x := LinkTarget { z := 1 } };
+            """)
+
     async def test_edgeql_ddl_link_computable_circular_01(self):
         await self.con.execute('''\
             CREATE TYPE CompLinkCircular {


Code review comments:
diff_hunk: @@ -1211,6 +1211,17 @@ def _parse_computable(
                     context=srcctx,
                 )
 
+        if (
+            not isinstance(source, Pointer)
+            and not source.is_view(schema)  # type: ignore
+            and target.is_view(expression.irast.schema)
+        ):
+            raise errors.UnsupportedFeatureError(
+                f'including a shape on schema-defined computed pointers '
path: edb/schema/pointers.py
text: @user1:
We tend to avoid using "pointer" in user-facing messages and documentation, so let's spell "properties" or "links" depending on what is being defined.

@author:
oh, and in fact it is always a link