Bug 11941 – Errors when appending to aggregate member array in CTFE
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-17T14:39:00Z
Last change time
2014-01-22T16:58:25Z
Keywords
CTFE, pull, rejects-valid
Assigned to
nobody
Creator
nilsbossung
Comments
Comment #0 by nilsbossung — 2014-01-17T14:39:42Z
Works with 2.064.2.
Fails with v2.065-devel-2b521dd.
---
cat > test.d << code
alias E = string;
void takeConst(const E[]) {}
E[] identity(E[] x) {return x;}
static assert({
struct S
{
E[] a;
}
S s;
takeConst(identity(s.a));
version(A) s.a ~= [];
else version(B)
{
s.a ~= "foo"; /* Error refers to this line (15), */
E[] b = s.a[]; /* but only when this is here. */
}
return true;
}());
code
echo A; dmd -c -version=A test.d
echo B; dmd -c -version=B test.d
---
A
test.d(12): Error: Cannot interpret s.a ~= [] at compile time
test.d(20): called from here: (*() => true)()
test.d(4): while evaluating: static assert((*() => true)())
B
test.d(15): Error: array cast from string to string[] is not supported at compile time
test.d(20): called from here: (*() => true)()
test.d(4): while evaluating: static assert((*() => true)())
---