D issues are now
tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Summary: |
__dollar cannot be read at compile time |
Product: |
D
|
Reporter: |
bearophile_hugs |
Component: |
dmd | Assignee: |
No Owner <nobody> |
Status: |
RESOLVED
FIXED
|
Severity: |
normal
|
CC: |
bugzilla, clugdbug, code, degener_trash
|
Priority: |
P2
|
Keywords: |
CTFE, pull, rejects-valid |
Version: |
D2 |
Hardware: |
x86 |
OS: |
Windows |
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
Martin Nowak
2012年03月25日 17:38:04 UTC
D has no runtime initialization for static variables.
Therefor the initializer must be constant.
The error message could be better though.
Comment 2
Martin Nowak
2012年03月25日 17:48:06 UTC
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.
*** Issue 7771 has been marked as a duplicate of this issue. ***
*** Issue 8419 has been marked as a duplicate of this issue. ***