www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21080] New: [REG 2.080] Cannot initialize immutable variable


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

enum Enum

class Klass
    immutable Object wat;

    this (Enum value)
        final switch (value)
        case Enum.A:
        case Enum.B:
        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.

Jul 26 2020