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.
Comment #3 by clugdbug — 2012-04-04T11:51:42Z
Comment #4 by clugdbug — 2012-04-04T11:57:54Z
*** Issue 7771 has been marked as a duplicate of this issue. ***
Comment #5 by github-bugzilla — 2012-04-14T15:44:13Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/59ee1fa13ff8f921bfe45307ea595fae7ea51fa7 Fix issue 7770 __dollar cannot be read at compile time It is always a CTFE variable, even if in global scope. https://github.com/D-Programming-Language/dmd/commit/4ff8864319107a802430cc1117fb560a1dcd6383 Merge pull request #867 from donc/ctfe7770dollar Fix issue 7770 __dollar cannot be read at compile time
Comment #6 by clugdbug — 2012-07-24T07:10:28Z
*** Issue 8419 has been marked as a duplicate of this issue. ***