Repository: edgedb/edgedb

Issue:
Custom type in function variadic argument is not found in migration
- EdgeDB Version:  2.0+88c1706, 2.1+52c90a7

This fails:

```
edgedb> start migration to {
.......     module default {
.......         scalar type E extending enum<a, b, c>;
.......         function f(variadic e: E) -> bool using (true);
.......     }
....... };
OK: START MIGRATION
edgedb[tx]> populate migration;
OK: POPULATE MIGRATION
edgedb[tx]> commit migration;
edgedb error: InvalidReferenceError: type 'default::E' does not exist
```

But doing it separately succeeds:

```
edgedb> start migration to {
.......     module default {
.......         scalar type E extending enum<a, b, c>;
.......
.......     }
....... };
OK: START MIGRATION
edgedb[tx]> populate migration;
OK: POPULATE MIGRATION
edgedb[tx]> commit migration;
OK: COMMIT MIGRATION
edgedb> start migration to {
.......     module default {
.......         scalar type E extending enum<a, b, c>;
.......         function f(variadic e: E) -> bool using (true);
.......     }
....... };
OK: START MIGRATION
edgedb[tx]> populate migration;
OK: POPULATE MIGRATION
edgedb[tx]> commit migration;
OK: COMMIT MIGRATION
edgedb> \ds
module default {
    function f(variadic e: default::E) ->  std::bool using (true);
    scalar type E extending enum<a, b, c>;
};
```


Discussion:

Resolving patch:
diff --git a/edb/buildmeta.py b/edb/buildmeta.py
--- a/edb/buildmeta.py
+++ b/edb/buildmeta.py
@@ -44,7 +44,7 @@
 
 
 # Increment this whenever the database layout or stdlib changes.
-EDGEDB_CATALOG_VERSION = 2022_09_29_00_00
+EDGEDB_CATALOG_VERSION = 2022_09_29_00_01
 EDGEDB_MAJOR_VERSION = 3
 
 
diff --git a/edb/schema/functions.py b/edb/schema/functions.py
--- a/edb/schema/functions.py
+++ b/edb/schema/functions.py
@@ -858,12 +858,8 @@ def _get_fqname_quals(
         canonical_order = canonical_param_sort(schema, params)
         for param in canonical_order:
             pt = param.get_type_shell(schema)
-            if isinstance(pt, s_types.CollectionTypeShell):
-                quals.append(pt.get_schema_class_displayname())
-                pt_id = str(pt.get_id(schema))
-            else:
-                pt_id = str(pt.name)
 
+            pt_id = str(pt.get_name(schema))
             quals.append(pt_id)
             pk = param.get_kind(schema)
             if pk is ft.ParameterKind.NamedOnlyParam:


Test patch:
diff --git a/tests/test_edgeql_data_migration.py b/tests/test_edgeql_data_migration.py
--- a/tests/test_edgeql_data_migration.py
+++ b/tests/test_edgeql_data_migration.py
@@ -6678,6 +6678,14 @@ async def test_edgeql_migration_eq_function_16(self):
             ['^^SOME_NAME^^'],
         )
 
+    async def test_edgeql_migration_enum_and_var_function_01(self):
+        # Create an enum and a variadic function that references it
+        # in the same migration. Issue #4213.
+        await self.migrate(r"""
+            scalar type E extending enum<a, b, c>;
+            function f(variadic e: E) -> bool using (true);
+        """)
+
     async def test_edgeql_migration_eq_linkprops_01(self):
         await self.migrate(r"""
             type Child;
diff --git a/tests/test_edgeql_ddl.py b/tests/test_edgeql_ddl.py
--- a/tests/test_edgeql_ddl.py
+++ b/tests/test_edgeql_ddl.py
@@ -12289,6 +12289,17 @@ async def test_edgeql_ddl_rename_ref_function_04(self):
             type_refs=2,
         )
 
+    async def test_edgeql_ddl_rename_ref_function_05(self):
+        await self._simple_rename_ref_tests(
+            """
+            CREATE FUNCTION foo(x: array<Note>) -> str {
+                USING ('x')
+            }
+            """,
+            """DROP FUNCTION foo(x: array<default::Note>);""",
+            prop_refs=0,
+        )
+
     async def test_edgeql_ddl_rename_ref_default_01(self):
         await self._simple_rename_ref_tests(
             """