www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21414] New: Spurious "non-constant expression" error with

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

          Issue ID: 21414
           Summary: Spurious "non-constant expression" error with
                    immutable constructors
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

//////////////////// test.d ///////////////////
struct State
{
    string s;

    immutable this(string s)
    {
        this.s = s;
    }
}

// Error: non-constant expression "b"[]
immutable rootState = new immutable State("b");
///////////////////////////////////////////////

Works OK if you remove the constructor.

Works OK if you remove "immutable" (and make rootState __gshared).

Seems to be a regression, introduced in
https://github.com/dlang/dmd/pull/4719

--
Nov 21 2020