Repository: edgedb/edgedb

Issue:
unknown issue the cli produced the link of issue
<!-- Please search existing issues to avoid creating duplicates. -->

<!--
For the EdgeDB Version: run `edgedb query 'select sys::get_version_as_str()'` from your project directory (or run `select sys::get_version_as_str();` in the EdgeDB interactive shell).
For the EdgeDB CLI Version: Run `edgedb --version` from anywhere
-->

EdgeDB CLI 4.0.2+da2788e
- OS Version: macos monterey

Steps to Reproduce:
![default_esdl_—_playground](https://github.com/edgedb/edgedb/assets/98676093/c1144cd5-c1b9-4384-879f-9b03d25c8111)


there are some changes before the error, removed abstract from person db, scalar enum type of task status, overloaded name of employee and default value of name

Schema:
module default {
    type Person {
        required name: str;
        user: User;
        optional contact_info: ContactInfo;
    };

    type User {
        required username: str;
        created_at: datetime;
        optional password: str;
        required person: Person;
    };

    type ContactInfo {
        optional email: str;
        optional phone: str;
        optional second_phone: str;
        optional address: str;
        optional city: str;
        optional state: str;
        optional zipcode: str;
        optional country: str;
    };

    type Company {
        required name: str;
        optional website: str;
    };

    type Employee extending Person {
        required company:  Company;
        required salary: int32;
        multi tasks: Task;
    };

    type Task {
        required description: str;
        optional due_date: datetime;
        optional status: enum<pending, completed, in_progress, on_hold, cancelled>;
        multi assignee: Employee;
    };

    type Role {
        required name: str;
        description: str;
    };
};




Discussion:
I'm baffled we don't have a test for this!

What you've hit is a bug that masks the correct error message that you get if you try to convert your schema to DDL:

```
_localdev:edgedb> create type Task {
.................     create property status: enum<pending, completed, in_progress, on_hold, cancelled>;
................. };
error: InvalidPropertyDefinitionError: this type cannot be anonymous
  ┌─ <query>:2:33
  │
2 │         create property status: enum<pending, completed, in_progress, on_hold, cancelled>;
  │                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error
  │
  = you may want define this enum first:

      scalar type MyEnum extending enum<...>;
```


Resolving patch:
diff --git a/edb/edgeql/declarative.py b/edb/edgeql/declarative.py
--- a/edb/edgeql/declarative.py
+++ b/edb/edgeql/declarative.py
@@ -46,6 +46,7 @@
 from edb.edgeql import codegen as qlcodegen
 from edb.edgeql import parser as qlparser
 from edb.edgeql import tracer as qltracer
+from edb.edgeql import utils as qlutils
 
 from edb.schema import annos as s_anno
 from edb.schema import constraints as s_constr
@@ -1336,6 +1337,13 @@ def _get_hard_deps(
     deps: MutableSet[s_name.QualName] = set()
 
     if isinstance(expr, qlast.TypeName):
+
+        # Special case for `enum<VariantA, VariantB>`
+        # Don't trace at all, neither `enum` or `VariantA` are resolvable names.
+        # This case will fail later, saying that you need to declare a new type.
+        if qlutils.is_enum(expr):
+            return deps
+
         # We care about subtypes dependencies, because
         # they can either be custom scalars or illegal
         # ObjectTypes (then error message will depend on
@@ -1377,14 +1385,7 @@ def _get_bases(
 
     if decl.bases:
         # Explicit inheritance
-        has_enums = any(
-            (
-                isinstance(br.maintype, qlast.TypeName)
-                and br.maintype.name == "enum"
-                and br.subtypes
-            )
-            for br in decl.bases
-        )
+        has_enums = any(qlutils.is_enum(br) for br in decl.bases)
 
         if has_enums:
             if len(decl.bases) > 1:
diff --git a/edb/edgeql/utils.py b/edb/edgeql/utils.py
--- a/edb/edgeql/utils.py
+++ b/edb/edgeql/utils.py
@@ -214,3 +214,11 @@ def contains_dml(ql_expr: qlast.Base) -> bool:
     )
 
     return bool(res)
+
+
+def is_enum(type_name: qlast.TypeName):
+    return (
+        isinstance(type_name.maintype, (qlast.TypeName, qlast.ObjectRef))
+        and type_name.maintype.name == "enum"
+        and type_name.subtypes
+    )


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -676,6 +676,17 @@ def test_schema_bad_type_17(self):
         };
         """
 
+    @tb.must_fail(
+        errors.InvalidPropertyDefinitionError,
+        "this type cannot be anonymous",
+    )
+    def test_schema_bad_type_18(self):
+        """
+        type Foo {
+            property val -> enum<VariantA, VariantB>;
+        };
+        """
+
     def test_schema_computable_cardinality_inference_01(self):
         schema = self.load_schema("""
             type Object {