Skip to content

Stage 3 feedback: can we make the number of using decls that need disposal statically knowable? #215

@syg

Description

@syg

During implementation we realized the following cursed code is possible:

switch (lbl) {
  case 0:
    using x = init();
    break;
}

AFAIK other than this, declarations aren't conditionally evaluated inside a scope. This weirdness means that you have to check at runtime whether a binding actually has a disposable resource. It'd be nice if all using bindings are unconditionally disposed at scope exit.

While I appreciate that other binding forms are allowed in bare switch cases like that and changing this would break symmetry, using declarations already break symmetry elsewhere. Is there a reason to allow this pattern?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions