[Issue 21080] New: [REG 2.080] Cannot initialize immutable variable after switch

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 27 04:56:33 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21080

          Issue ID: 21080
           Summary: [REG 2.080] Cannot initialize immutable variable after
                    switch
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: industry
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: pro.mathias.lang at gmail.com

```
enum Enum
{
    A,
    B,
}

class Klass
{
    immutable Object wat;

    this (Enum value)
    {
        final switch (value)
        {
        case Enum.A:
        case Enum.B:
            break;
        }
        this.wat = new immutable Object();
    }
}
void main() {}
```

According to run.dlang.org:
```
2.061   to 2.079.1: Success and no output
Since      2.080.1: Failure with output: onlineapp.d(19): Error: immutable
field `wat` initialization is not allowed in loops or after labels
```

Moving the initialization before the switch works.

--


More information about the Digitalmars-d-bugs mailing list