Bug 7770 – __dollar cannot be read at compile time
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-03-25T12:18:00Z
Last change time
2012-07-24T07:10:28Z
Keywords
CTFE, pull, rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-03-25T12:18:47Z
D2 code:
import std.ascii: uppercase;
import std.string: maketrans;
void main() {
static r = maketrans(uppercase, uppercase[0 .. $]);
}
DMD 2.059head:
test.d(4): Error: variable __dollar cannot be read at compile time
test.d(4): called from here: maketrans(cast(const(char[]))uppercase,cast(const(char[]))uppercase[0u..__dollar])
Comment #1 by code — 2012-03-25T17:38:04Z
D has no runtime initialization for static variables.
Therefor the initializer must be constant.
The error message could be better though.
Comment #2 by code — 2012-03-25T17:48:06Z
cat > bug.d << CODE
immutable char[5] foo = "abcde";
int bar(string a, string b)
{
return 0;
}
void baz()
{
enum s = bar(foo, foo[0 .. $]);
}
// Assertion failed: (!v->isDataseg() || v->isCTFE()), function push, file interpret.c, line 108.
version (none)
enum s = bar(foo, foo[0 .. $]);
CODE
dmd -c bug
--------
Sorry, you're point was obviously that __dollar should be resolvable
at compile time.