July 27, 2020 [Issue 21080] New: [REG 2.080] Cannot initialize immutable variable after switch | ||||
---|---|---|---|---|
| ||||
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@puremagic.com Reporter: pro.mathias.lang@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. -- |
Copyright © 1999-2021 by the D Language Foundation