[Issue 7940] CTFE breaks
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Apr 21 13:06:09 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7940
SomeDude <lovelydear at mailmetrash.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lovelydear at mailmetrash.com
Platform|x86_64 |All
OS/Version|Linux |All
--- Comment #1 from SomeDude <lovelydear at mailmetrash.com> 2012-04-21 13:07:06 PDT ---
Same code as above, very slightly simplified.
-----------------
import std.typecons : Tuple;
import std.array : appender;
import std.stdio : writeln;
struct S {
Tuple!(uint, double)[] _data;
alias _data this;
}
private auto gen(K, V)(V[K] data) {
alias Tuple!(K, V) T;
auto app = appender!(T[]);
foreach(k, v; data) app.put(T(k, v));
return app.data;
}
auto s(double[uint] data) {
return S(gen!(uint, double)(data));
}
void main() {
static S s1 = s([1: 12.0, 5: 4.6, 3: 9.99]);
S s2 = s([1: 12.0, 5: 4.6, 3: 9.99]);
writeln(s1);
writeln(s2);
}
------------------
PS E:\DigitalMars\dmd2\samples> rdmd -g bug.d
[Tuple!(uint,double)(0, nan), Tuple!(uint,double)(0, nan),
Tuple!(uint,double)(0, nan)]
[Tuple!(uint,double)(1, 12), Tuple!(uint,double)(3, 9.99),
Tuple!(uint,double)(5, 4.6)]
If we remove the static, it works.
If we replace the appender by an array in:
import std.typecons : Tuple;
import std.array : appender;
import std.stdio : writeln;
struct S {
Tuple!(uint, double)[] _data;
alias _data this;
}
private auto gen(K, V)(V[K] data) {
alias Tuple!(K, V) T;
T[] app;
foreach(k, v; data) app ~= T(k, v);
return app;
}
auto s(double[uint] data) {
return S(gen!(uint, double)(data));
}
void main() {
static S s1 = s([1: 12.0, 5: 4.6, 3: 9.99]);
S s2 = s([1: 12.0, 5: 4.6, 3: 9.99]);
writeln(s1);
writeln(s2);
}
PS E:\DigitalMars\dmd2\samples> rdmd -g bug.d
[Tuple!(uint,double)(1, 12), Tuple!(uint,double)(5, 4.6),
Tuple!(uint,double)(3, 9.99)]
[Tuple!(uint,double)(1, 12), Tuple!(uint,double)(3, 9.99),
Tuple!(uint,double)(5, 4.6)]
If we remove the static:
PS E:\DigitalMars\dmd2\samples> rdmd -g bug.d
[Tuple!(uint,double)(1, 12), Tuple!(uint,double)(3, 9.99),
Tuple!(uint,double)(5, 4.6)]
[Tuple!(uint,double)(1, 12), Tuple!(uint,double)(3, 9.99),
Tuple!(uint,double)(5, 4.6)]
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list