7770 – __dollar cannot be read at compile time

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7770 - __dollar cannot be read at compile time
Summary: __dollar cannot be read at compile time
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: CTFE, pull, rejects-valid
: 7771 8419 (view as issue list)
Depends on:
Blocks:
Reported: 2012年03月25日 12:18 UTC by bearophile_hugs
Modified: 2012年07月24日 07:10 UTC (History)
4 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012年03月25日 12:18:47 UTC
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.
Comment 4 Don 2012年04月04日 11:57:54 UTC
*** Issue 7771 has been marked as a duplicate of this issue. ***
Comment 5 github-bugzilla 2012年04月14日 15:44:13 UTC
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 Don 2012年07月24日 07:10:28 UTC
*** Issue 8419 has been marked as a duplicate of this issue. ***


AltStyle によって変換されたページ (->オリジナル) /