Bug 640 – Strage error messages around structInstance.init

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2006-12-03T11:23:00Z
Last change time
2014-02-15T13:19:19Z
Assigned to
bugzilla
Creator
kinaba

Comments

Comment #0 by kinaba — 2006-12-03T11:23:40Z
// credit goes to http://pc8.2ch.net/test/read.cgi/tech/1158013550/956 struct A { int a; } void main() { A x; // <-- test.d(3) x = x.init; } ---------------- test.d(3): Error: cannot implicitly convert expression (0) of type int to A test.d(3): Error: cannot cast int to A If x=x.init is commented out, or changed to x=A.init, the error disappears. Even worse, a slightly modified version crashes dmd (access violation). struct A { int a; } void main() { A x = {0}; x = x.init; }
Comment #1 by thomas-dloop — 2006-12-10T11:06:41Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb am 2006-12-03: > http://d.puremagic.com/issues/show_bug.cgi?id=640 > // credit goes to http://pc8.2ch.net/test/read.cgi/tech/1158013550/956 > struct A { int a; } > void main() { > A x; // <-- test.d(3) > > x = x.init; > } > ---------------- > test.d(3): Error: cannot implicitly convert expression (0) of type int to A > test.d(3): Error: cannot cast int to A > > > If x=x.init is commented out, or changed to x=A.init, the error disappears. > Even worse, a slightly modified version crashes dmd (access violation). > > struct A { int a; } > void main() { > A x = {0}; > x = x.init; > } Added to DStress as http://dstress.kuehne.cn/nocompile/b/expression_4154_A.d http://dstress.kuehne.cn/nocompile/b/expression_4154_B.d http://dstress.kuehne.cn/run/b/expression_4154_C.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFfEFVLK5blCcjpWoRAudDAJ99lH4s96OIIp3kKTdU4Eab2raSvgCdHlFh JRhifgfKTSJpL6tdKxLodEE= =LyJw -----END PGP SIGNATURE-----
Comment #2 by thomas-dloop — 2007-04-27T12:36:28Z
Comment #3 by kinaba — 2007-07-12T23:49:03Z
The spec introduced at D 2.001/1.017 > The .init property for a variable is now based on its type, not its initializer. fixed this problem.