Bug 21080 – [REG 2.080] Cannot initialize immutable variable after switch

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-27T04:56:33Z
Last change time
2024-12-13T19:10:26Z
Keywords
industry
Assigned to
No Owner
Creator
Mathias LANG
Moved to GitHub: dmd#17975 →

Comments

Comment #0 by pro.mathias.lang — 2020-07-27T04:56:33Z
``` 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.
Comment #1 by moonlightsentinel — 2020-07-27T09:41:23Z
Comment #2 by robert.schadek — 2024-12-13T19:10:26Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17975 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB