|
39 | 39 | from edb.schema import globals as s_globals |
40 | 40 | from edb.schema import indexes as s_indexes |
41 | 41 | from edb.schema import name as sn |
| 42 | +from edb.schema import objects as so |
42 | 43 | from edb.schema import objtypes as s_objtypes |
| 44 | +from edb.schema import permissions as s_permissions |
43 | 45 | from edb.schema import pseudo as s_pseudo |
44 | 46 | from edb.schema import scalars as s_scalars |
| 47 | +from edb.schema import schema as s_schema |
45 | 48 | from edb.schema import types as s_types |
46 | 49 | from edb.schema import utils as s_utils |
47 | 50 | from edb.schema import expr as s_expr |
@@ -549,10 +552,56 @@ def compile_UnaryOp( |
549 | 552 | def compile_GlobalExpr( |
550 | 553 | expr: qlast.GlobalExpr, *, ctx: context.ContextLevel |
551 | 554 | ) -> irast.Set: |
552 | | - glob = ctx.env.get_schema_object_and_track( |
553 | | - s_utils.ast_ref_to_name(expr.name), expr.name, |
554 | | - modaliases=ctx.modaliases, type=s_globals.Global) |
555 | | - assert isinstance(glob, s_globals.Global) |
| 555 | + # The expr object can be either a Permission or Global. |
| 556 | + # Get an Object and manually check for correct type and None. |
| 557 | + expr_schema_name = s_utils.ast_ref_to_name(expr.name) |
| 558 | + expr_obj = ctx.env.get_schema_object_and_track( |
| 559 | + expr_schema_name, |
| 560 | + expr.name, |
| 561 | + default=None, |
| 562 | + modaliases=ctx.modaliases, |
| 563 | + type=so.Object, |
| 564 | + ) |
| 565 | + |
| 566 | + # Check for None first. |
| 567 | + if expr_obj is None: |
| 568 | + # If no object is found, we want to raise an error with 'global' as |
| 569 | + # the desired type. |
| 570 | + # If we let `get_schema_object_and_track`, the error will contain |
| 571 | + # 'object' instead. |
| 572 | + s_schema.Schema.raise_bad_reference( |
| 573 | + expr_schema_name, |
| 574 | + module_aliases=ctx.modaliases, |
| 575 | + span=expr.span, |
| 576 | + type=s_globals.Global, |
| 577 | + ) |
| 578 | + |
| 579 | + # Check for permission |
| 580 | + if isinstance(expr_obj, s_permissions.Permission): |
| 581 | + std_type = sn.QualName('std', 'bool') |
| 582 | + ct = typegen.type_to_typeref( |
| 583 | + ctx.env.get_schema_type_and_track(std_type), |
| 584 | + env=ctx.env, |
| 585 | + ) |
| 586 | + ir_expr = irast.BooleanConstant( |
| 587 | + value="false", typeref=ct, span=expr.span |
| 588 | + ) |
| 589 | + return setgen.ensure_set(ir_expr, ctx=ctx) |
| 590 | + |
| 591 | + # Check for non-global |
| 592 | + if not isinstance(expr_obj, s_globals.Global): |
| 593 | + s_schema.Schema.raise_wrong_type( |
| 594 | + expr_schema_name, |
| 595 | + expr_obj.__class__, |
| 596 | + s_globals.Global, |
| 597 | + span=expr.span, |
| 598 | + ) |
| 599 | + # Raise an error here so mypy knows that expr_obj can only be a global |
| 600 | + # past this point. |
| 601 | + raise AssertionError('should never happen') |
| 602 | + |
| 603 | + # Non-permission global |
| 604 | + glob = expr_obj |
556 | 605 |
|
557 | 606 | if glob.is_computable(ctx.env.schema): |
558 | 607 | obj_ref = s_utils.name_to_ast_ref( |
|
0 commit comments