[Issue 18945] New: immutable variable is used as if it's an enum
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jun 5 10:39:33 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18945
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 at puremagic.com
Reporter: simen.kjaras at 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'.
--
More information about the Digitalmars-d-bugs
mailing list