# Buggy code
def compile_Set(
    ir_set: irast.Set, *, ctx: context.CompilerContextLevel
) -> pgast.BaseExpr:
    if ctx.singleton_mode:
        return _compile_set_in_singleton_mode(ir_set, ctx=ctx)

    is_toplevel = ctx.toplevel_stmt is context.NO_STMT

    _compile_set_impl(ir_set, ctx=ctx)

    if is_toplevel:
        if isinstance(ir_set.expr, irast.ConfigCommand):
            return config.top_output_as_config_op(ir_set, ctx.rel, env=ctx.env)
        else:
            return output.top_output_as_value(ctx.rel, ir_set, env=ctx.env)
    else:
        value = pathctx.get_path_value_var(ctx.rel, ir_set.path_id, env=ctx.env)

        return output.output_as_value(value, env=ctx.env)


# Traceback (edb.errors.InternalServerError)
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/procpool/worker.py", line 75, in worker
res = await meth(*args)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1816, in compile_eql_tokens_in_tx
return self._compile(ctx=ctx, tokens=eql_tokens)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1429, in _compile
comp: dbstate.BaseQuery = self._compile_dispatch_ql(ctx, stmt)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1352, in _compile_dispatch_ql
return self._compile_ql_migration(ctx, ql)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1047, in _compile_ql_migration
ddl_query = self._compile_and_apply_ddl_stmt(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 752, in _compile_and_apply_ddl_stmt
block, new_types = self._process_delta(ctx, delta)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 412, in _process_delta
schema = delta.apply(schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 4027, in apply
schema = sd.DeltaRoot.apply(self, schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/schema/delta.py", line 1094, in apply
schema = objop.apply(schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 194, in apply
schema = self.__class__.get_adaptee().apply(self, schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/schema/delta.py", line 2037, in apply
schema = self._create_innards(schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/schema/delta.py", line 2005, in _create_innards
schema = op.apply(schema, context=context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 595, in apply
schema, op = self.make_op(self.scls, schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 575, in make_op
dbf = self.compile_edgeql_function(func, schema, context)
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/delta.py", line 546, in compile_edgeql_function
sql_text, _ = compiler.compile_ir_to_sql(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/compiler/__init__.py", line 105, in compile_ir_to_sql
qtree = compile_ir_to_sql_tree(
File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha5/lib/python3.8/site-packages/edb/pgsql/compiler/__init__.py", line 90, in compile_ir_to_sql_tree
raise errors.InternalServerError(*args) from e
edb.errors.InternalServerError: list index out of range

# Fixed code
def compile_Set(
    ir_set: irast.Set, *, ctx: context.CompilerContextLevel
) -> pgast.BaseExpr:
    if ctx.singleton_mode:
        return _compile_set_in_singleton_mode(ir_set, ctx=ctx)

    is_toplevel = ctx.toplevel_stmt is context.NO_STMT

    _compile_set_impl(ir_set, ctx=ctx)

    if is_toplevel:
        if isinstance(ir_set.expr, irast.ConfigCommand):
            return config.top_output_as_config_op(ir_set, ctx.rel, env=ctx.env)
        else:
            pathctx.get_path_serialized_output(ctx.rel, ir_set.path_id, env=ctx.env)
            return output.top_output_as_value(ctx.rel, ir_set, env=ctx.env)
    else:
        value = pathctx.get_path_value_var(ctx.rel, ir_set.path_id, env=ctx.env)

        return output.output_as_value(value, env=ctx.env)