www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18945] New: immutable variable is used as if it's an enum


          Issue ID: 18945
           Summary: immutable variable is used as if it's an enum
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: CTFE
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: simen.kjaras gmail.com

unittest {
    immutable n = __ctfe ? 1 : 2;
    int[n] a;
    assert(a.length == n);

The above assert fails - the value of n is calculated using CTFE for the length
of a, and is thus set to 1. Then, at runtime, the value of n is set to 2, and
the assert fails.

It seems to me the issue is that the variable n is being used as a compile-time
constant. The expected behavior is an error message along the lines of
'variable n cannot be read at compile time'.

Jun 05 2018