digitalmars.D.bugs - [Issue 7912] New: Cannot read compile variable at compile time
- d-bugmail puremagic.com (54/59) Apr 14 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7912
- d-bugmail puremagic.com (11/11) Apr 14 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7912
- d-bugmail puremagic.com (14/14) Apr 14 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7912
- d-bugmail puremagic.com (10/10) Apr 21 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7912
- d-bugmail puremagic.com (10/10) Apr 23 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7912
http://d.puremagic.com/issues/show_bug.cgi?id=7912 Summary: Cannot read compile variable at compile time Product: D Version: D2 Platform: x86 OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: jazeik gmail.com --- Comment #0 from Jan <jazeik gmail.com> 2012-04-14 13:53:23 PDT --- tst.d ---------------------------- import std.stdio; import std.conv; mixin template TTT() { static const uint tst; static this() { tst = 0; } } class T { mixin TTT; } void main() { auto n = 0; switch(n) { case T.tst: writeln("T.tst: ", T.tst); break; default: writeln("default: ", n); break; } } ---------------------------- Run with:dmd -run tst.d============================= result:tst.d(23): Error: variable tst cannot be read at compile time tst.d(23): Error: variable tst cannot be read at compile time tst.d(23): Error: case must be a string or an integral constant, not cast(int)tst============================= Expected result:T.tst: 0============================= Additional Information: Replace "switch(n)" with "switch(n | (T.tst))" to get expected result. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 14 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7912 Matt Peterson <revcompgeek gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |revcompgeek gmail.com --- Comment #1 from Matt Peterson <revcompgeek gmail.com> 2012-04-14 21:01:59 PDT --- tst is not a compile time variable, it is a runtime variable. This issue is invalid. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 14 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7912 --- Comment #2 from Matt Peterson <revcompgeek gmail.com> 2012-04-14 21:09:04 PDT --- Jan: If you want tst to be compile time, use enum instead of const, and just do "enum uint tst = 0;" or even "enum tst = 0;". The module constructor (static this() {...}) is called at runtime, and can do a variety of things, including getting input from the console and other things that the compiler can't evaluate at compile time. Since you didn't give a value at the declaration of tst, D requires you to set it in the module constructor as you have done, but it's not a value that can be read at compile time. I believe if you were to have done "static const uint tst = 0;" instead, it would have worked, but using enum instead is a good way to force a variable to be compile time evaluated. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 14 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7912 SomeDude <lovelydear mailmetrash.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lovelydear mailmetrash.com --- Comment #3 from SomeDude <lovelydear mailmetrash.com> 2012-04-21 11:57:38 PDT --- Invalid issue ? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 21 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7912 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug yahoo.com.au Resolution| |INVALID -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 23 2012