Bug 5865 – __dollar cannot be read at compile time

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2011-04-19T18:06:00Z
Last change time
2011-04-30T11:30:48Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
changlon

Comments

Comment #0 by changlon — 2011-04-19T18:06:47Z
this working on dmd 2.052 release, throw error on dmd git master . ------------------------------------------ class Test1(string name, string file = __FILE__){ static const _file = file ; void test1(){ static const string file2 = _file[0..$] ; } } void main(){ auto obj = new Test1!"Test1" ; obj.test1(); } ----------------------------------------- test.d(5): Error: variable __dollar cannot be read at compile time test.d(5): Error: variable __dollar cannot be read at compile time test.d(10): Error: template instance test.Test1!("Test1") error instantiating
Comment #1 by clugdbug — 2011-04-20T02:06:21Z
PATCH dsymbol.c, line 1181. if (!*pvar) // if not already initialized { /* Create variable v and set it to the value of $, * which will be a constant. */ VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); if (ce->op == TOKvar) { // if ce is const, get its initializer - ce = fromConstInitializer(WANTvalue, ce); + ce = fromConstInitializer(WANTvalue | WANTexpand, ce); } if (ce->op == TOKstring) { /* It is for a string literal, so the * length will be a const. */
Comment #2 by bugzilla — 2011-04-30T10:43:21Z
Comment #3 by bugzilla — 2011-04-30T11:30:48Z