digitalmars.D.learn - Anonymous nested class of problems
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (30/30) Dec 12 2009 I was playing with what makes the Javists proud, but stumbled over this:
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (10/11) Dec 12 2009 This one seems to be unrelated to anonymous stuff.
- div0 (23/41) Dec 12 2009 -----BEGIN PGP SIGNED MESSAGE-----
- =?utf-8?B?VG9tZWsgU293acWEc2tp?= (7/38) Dec 12 2009 =B3(a):
- div0 (17/59) Dec 12 2009 -----BEGIN PGP SIGNED MESSAGE-----
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (24/39) Dec 12 2009 It's not only about anonymous classes. Take a look at this:
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (10/48) Dec 12 2009 =
I was playing with what makes the Javists proud, but stumbled over this: class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; static m = new class(4) M { this(byte a) { super(a); } override byte a() { return 3+_a; } }; } Error: class test.M.__anonclass10 has forward references Error: no constructor for __anonclass10 Is this a compiler bug? There's no reason why the above shouldn't compile, no? But that's not all, when I mark my class immutable... immutable class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; } void main() { auto m = new class(4) M { this(byte a) { super(a); } override byte a() { return 3+_a; } }; } ... the compiler says: cannot implicitly convert expression (this) of type immutable(M) to test.M. Same story for const classes. Again, compiler bug? Tomek
Dec 12 2009
Dnia 12-12-2009 o 13:09:49 Tomek Sowi=F1ski <just ask.me> napisa=B3(a):Error: no constructor for __anonclass10This one seems to be unrelated to anonymous stuff. class M { this(byte a) { _a =3D a; } byte _a; byte a() { return _a; }; static m =3D new M(3); } I get: Error: no constructor for M. Tomek
Dec 12 2009
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Tomek Sowiński wrote:Dnia 12-12-2009 o 13:09:49 Tomek Sowiński <just ask.me> napisa³(a):Well for this one, you're doing it wrong. You want: class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; static M m; static this() { m = new M(3); } } - -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFLI6IYT9LetA9XoXwRAmmrAKCQYcX8qyXXxYMau4gVyAbEM3PWpACfS0uU 1wc11d9lU608J+ZSiEH77AE= =svdA -----END PGP SIGNATURE-----Error: no constructor for __anonclass10This one seems to be unrelated to anonymous stuff. class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; static m = new M(3); } I get: Error: no constructor for M. Tomek
Dec 12 2009
Dnia 12-12-2009 o 15:00:56 div0 <div0 users.sourceforge.net> napisa=C5=82= (a):-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Tomek Sowi=C3=B1ski wrote:=B3(a):Dnia 12-12-2009 o 13:09:49 Tomek Sowi=C3=B1ski <just ask.me> napisa=C2=So it's the same when I get the "non-constant expression..." error and = have to put in static ctors? Then what's with the "no constructor for M"= ? TomekWell for this one, you're doing it wrong. You want: class M { this(byte a) { _a =3D a; } byte _a; byte a() { return _a; }; static M m; static this() { m =3D new M(3); } }Error: no constructor for __anonclass10This one seems to be unrelated to anonymous stuff. class M { this(byte a) { _a =3D a; } byte _a; byte a() { return _a; }; static m =3D new M(3); } I get: Error: no constructor for M. Tomek
Dec 12 2009
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Tomek SowiÅski wrote:Dnia 12-12-2009 o 15:00:56 div0 <div0 users.sourceforge.net> napisaĆ ā(a):Yes I think.-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Tomek SowiĆĀ±ski wrote:So it's the same when I get the "non-constant expression..." error and have to put in static ctors?Dnia 12-12-2009 o 13:09:49 Tomek SowiĆĀ±ski <just ask.me> napisaĆĀ³(a):Well for this one, you're doing it wrong. You want: class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; static M m; static this() { m = new M(3); } }Error: no constructor for __anonclass10This one seems to be unrelated to anonymous stuff. class M { this(byte a) { _a = a; } byte _a; byte a() { return _a; }; static m = new M(3); } I get: Error: no constructor for M. TomekThen what's with the "no constructor for M"?Don't know. It's best not to read too much into DMDs error messages, they leave a lot to be desired. - -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFLJB/3T9LetA9XoXwRAtSOAJ9tOP6uJiL6bvxtKZmiW8EMTDmOcQCfbOxs 6f+K154WRQu9NkYKdcDJ2fU= =ueMn -----END PGP SIGNATURE-----
Dec 12 2009
Dnia 12-12-2009 o 13:09:49 Tomek Sowi=F1ski <just ask.me> napisa=B3(a):But that's not all, when I mark my class immutable... immutable class M { this(byte a) { _a =3D a; } byte _a; byte a() { return _a; }; } void main() { auto m =3D new class(4) M { this(byte a) { super(a); } override byte a() { return 3+_a; } }; } ... the compiler says: cannot implicitly convert expression (this) of ==type immutable(M) to test.M. Same story for const classes. Again, compiler bug?It's not only about anonymous classes. Take a look at this: immutable class M { this(int a) { _a =3D a; } int _a; int a() { return _a; } } immutable class PodM : M { this(int a) { super(a); } override int a() { return 3+_a; } } void main() { auto m =3D new PodM(3); } The above still throws the same error: Error: cannot implicitly convert expression (this) of type immutable(M) = to = test.M Error: cannot implicitly convert expression (this) of type immutable(Pod= M) = to test.PodM Compiler bug I guess... Tomek
Dec 12 2009
Dnia 13-12-2009 o 00:44:56 Tomek Sowi=F1ski <just ask.me> napisa=B3(a):Dnia 12-12-2009 o 13:09:49 Tomek Sowi=F1ski <just ask.me> napisa=B3(a)=:=But that's not all, when I mark my class immutable... immutable class M { this(byte a) { _a =3D a; } byte _a; byte a() { return _a; }; } void main() { auto m =3D new class(4) M { this(byte a) { super(a); } override byte a() { return 3+_a; } }; } ... the compiler says: cannot implicitly convert expression (this) of=) =type immutable(M) to test.M. Same story for const classes. Again, compiler bug?It's not only about anonymous classes. Take a look at this: immutable class M { this(int a) { _a =3D a; } int _a; int a() { return _a; } } immutable class PodM : M { this(int a) { super(a); } override int a() { return 3+_a; } } void main() { auto m =3D new PodM(3); } The above still throws the same error: Error: cannot implicitly convert expression (this) of type immutable(M=to test.M Error: cannot implicitly convert expression (this) of type =immutable(PodM) to test.PodM Compiler bug I guess...Should've DAFS first... http://d.puremagic.com/issues/show_bug.cgi?id=3D2610 What's disturbing is that this bug is nearly a year old... Could this be= = that immutable classes lay there virtually unusable for so long? Tomek
Dec 12 2009