digitalmars.D.learn - struct init() method
- bearophile (12/12) Feb 24 2012 This program comes from a reduction of a bug I've found:
- =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= (5/17) Feb 25 2012 IMHO we shouldn't allow having *any* members that use the same name as
- H. S. Teoh (7/28) Feb 25 2012 [...]
- Timon Gehr (5/30) Feb 25 2012 This is useful:
- Jonathan M Davis (4/9) Feb 25 2012 I thought that the way that you were supposed to do that was
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (4/13) Feb 25 2012 Yeah, I'm not sure what purpose the other example serves.
- H. S. Teoh (8/23) Feb 25 2012 [...]
- Jonathan M Davis (13/35) Feb 25 2012 :-)
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (4/35) Feb 25 2012 Yep, exactly.
- Timon Gehr (3/12) Feb 26 2012 struct S{@disable this();}
- Jonathan M Davis (4/22) Feb 26 2012 Well, that's a problem then. It looks like it's bug - either that or I
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (5/27) Feb 26 2012 IMHO .init should yield an error for structs with @disable this().
- Jonathan M Davis (13/41) Feb 26 2012 s.
- Dmitry Olshansky (5/17) Feb 25 2012 FWIW I've encountered this thingy while messing with phobos std.file
This program comes from a reduction of a bug I've found: struct Foo { void init() {} } void main() { Foo*[] foos; //(*foos[0]).init(); // OK foos[0].init(); // Error: function expected before (), not null of type Foo* } What do you think about the idea of not allowing methods named init() in structs? (Especially if they are a property). Or maybe there is a better solution, opinions welcome. Bye, bearophile
Feb 24 2012
On 25-02-2012 05:05, bearophile wrote:This program comes from a reduction of a bug I've found: struct Foo { void init() {} } void main() { Foo*[] foos; //(*foos[0]).init(); // OK foos[0].init(); // Error: function expected before (), not null of type Foo* } What do you think about the idea of not allowing methods named init() in structs? (Especially if they are a property). Or maybe there is a better solution, opinions welcome. Bye, bearophileIMHO we shouldn't allow having *any* members that use the same name as any of the compiler-provided properties/functions. -- - Alex
Feb 25 2012
On Sat, Feb 25, 2012 at 01:23:21PM +0100, Alex Rønne Petersen wrote:On 25-02-2012 05:05, bearophile wrote:[...] Agreed. T -- Marketing: the art of convincing people to pay for what they didn't need before which you can't deliver after.This program comes from a reduction of a bug I've found: struct Foo { void init() {} } void main() { Foo*[] foos; //(*foos[0]).init(); // OK foos[0].init(); // Error: function expected before (), not null of type Foo* } What do you think about the idea of not allowing methods named init() in structs? (Especially if they are a property). Or maybe there is a better solution, opinions welcome. Bye, bearophileIMHO we shouldn't allow having *any* members that use the same name as any of the compiler-provided properties/functions.
Feb 25 2012
On 02/25/2012 04:52 PM, H. S. Teoh wrote:On Sat, Feb 25, 2012 at 01:23:21PM +0100, Alex Rønne Petersen wrote:This is useful: struct S{ disable enum init = 0; }On 25-02-2012 05:05, bearophile wrote:[...] Agreed. TThis program comes from a reduction of a bug I've found: struct Foo { void init() {} } void main() { Foo*[] foos; //(*foos[0]).init(); // OK foos[0].init(); // Error: function expected before (), not null of type Foo* } What do you think about the idea of not allowing methods named init() in structs? (Especially if they are a property). Or maybe there is a better solution, opinions welcome. Bye, bearophileIMHO we shouldn't allow having *any* members that use the same name as any of the compiler-provided properties/functions.
Feb 25 2012
On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:This is useful: struct S{ disable enum init = 0; }I thought that the way that you were supposed to do that was disable this(); - Jonathan M Davis
Feb 25 2012
On 26-02-2012 00:18, Jonathan M Davis wrote:On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:Yeah, I'm not sure what purpose the other example serves. -- - AlexThis is useful: struct S{ disable enum init = 0; }I thought that the way that you were supposed to do that was disable this(); - Jonathan M Davis
Feb 25 2012
On Sun, Feb 26, 2012 at 12:23:47AM +0100, Alex Rønne Petersen wrote:On 26-02-2012 00:18, Jonathan M Davis wrote:[...] It serves to prove that we need to disallow 'init' as a member name. :-) T -- Skill without imagination is craftsmanship and gives us many useful objects such as wickerwork picnic baskets. Imagination without skill gives us modern art. -- Tom StoppardOn Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:Yeah, I'm not sure what purpose the other example serves.This is useful: struct S{ disable enum init = 0; }I thought that the way that you were supposed to do that was disable this(); - Jonathan M Davis
Feb 25 2012
On Saturday, February 25, 2012 17:54:44 H. S. Teoh wrote:On Sun, Feb 26, 2012 at 12:23:47AM +0100, Alex R=C3=B8nne Petersen wr=ote::-) No. I think that he meant that he doesn't know what purpose disable enum init =3D 0; serves given that disable this(); already disables the init property. The fact that you're able to overri= de init=20 is a separate, albeit related issue. But yes, it should be disallowed t= o=20 declare any symbol as a member of a struct or class with the name init.= - Jonathan M DavisOn 26-02-2012 00:18, Jonathan M Davis wrote:=20 [...] =20 It serves to prove that we need to disallow 'init' as a member name. =On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:=20 Yeah, I'm not sure what purpose the other example serves.This is useful: struct S{ disable enum init =3D 0; }I thought that the way that you were supposed to do that was disable this(); - Jonathan M Davis
Feb 25 2012
On 26-02-2012 02:54, Jonathan M Davis wrote:On Saturday, February 25, 2012 17:54:44 H. S. Teoh wrote:Yep, exactly. -- - AlexOn Sun, Feb 26, 2012 at 12:23:47AM +0100, Alex Rønne Petersen wrote:No. I think that he meant that he doesn't know what purpose disable enum init = 0; serves given that disable this(); already disables the init property. The fact that you're able to override init is a separate, albeit related issue. But yes, it should be disallowed to declare any symbol as a member of a struct or class with the name init. - Jonathan M DavisOn 26-02-2012 00:18, Jonathan M Davis wrote:[...] It serves to prove that we need to disallow 'init' as a member name. :-)On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:Yeah, I'm not sure what purpose the other example serves.This is useful: struct S{ disable enum init = 0; }I thought that the way that you were supposed to do that was disable this(); - Jonathan M Davis
Feb 25 2012
On 02/26/2012 12:18 AM, Jonathan M Davis wrote:On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:struct S{ disable this();} void main(){S s = S.init;}This is useful: struct S{ disable enum init = 0; }I thought that the way that you were supposed to do that was disable this(); - Jonathan M Davis
Feb 26 2012
On Sunday, February 26, 2012 12:48:06 Timon Gehr wrote:On 02/26/2012 12:18 AM, Jonathan M Davis wrote:Well, that's a problem then. It looks like it's bug - either that or I completely misunderstood what was going on with disable and structs. - Jonathan M DavisOn Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:struct S{ disable this();} void main(){S s = S.init;}This is useful: struct S{ disable enum init = 0; }I thought that the way that you were supposed to do that was disable this(); - Jonathan M Davis
Feb 26 2012
On 26-02-2012 12:53, Jonathan M Davis wrote:On Sunday, February 26, 2012 12:48:06 Timon Gehr wrote:IMHO .init should yield an error for structs with disable this(). Anything else seems illogical. -- - AlexOn 02/26/2012 12:18 AM, Jonathan M Davis wrote:Well, that's a problem then. It looks like it's bug - either that or I completely misunderstood what was going on with disable and structs. - Jonathan M DavisOn Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:struct S{ disable this();} void main(){S s = S.init;}This is useful: struct S{ disable enum init = 0; }I thought that the way that you were supposed to do that was disable this(); - Jonathan M Davis
Feb 26 2012
On Sunday, February 26, 2012 13:15:51 Alex R=C3=B8nne Petersen wrote:On 26-02-2012 12:53, Jonathan M Davis wrote:r IOn Sunday, February 26, 2012 12:48:06 Timon Gehr wrote:On 02/26/2012 12:18 AM, Jonathan M Davis wrote:=20 Well, that's a problem then. It looks like it's bug - either that o=On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote:=20 struct S{ disable this();} void main(){S s =3D S.init;}This is useful: =20 struct S{ =20 disable enum init =3D 0; =20 }=20 I thought that the way that you were supposed to do that was =20 disable this(); =20 - Jonathan M Daviss.completely misunderstood what was going on with disable and struct=Well, like I said, it's my understanding that disable this() is the wa= y that=20 you're supposed to disable .init - as in that's the whole point of havi= ng=20 added disable this() to the language (though it can also be used to ma= ke=20 classes unconstructable). So, either my understanding is wrong and/or t= his is=20 a bug. - Jonathan M Davis=20 - Jonathan M Davis=20 IMHO .init should yield an error for structs with disable this(). Anything else seems illogical.
Feb 26 2012
On 25.02.2012 8:05, bearophile wrote:This program comes from a reduction of a bug I've found: struct Foo { void init() {} } void main() { Foo*[] foos; //(*foos[0]).init(); // OK foos[0].init(); // Error: function expected before (), not null of type Foo* } What do you think about the idea of not allowing methods named init() in structs? (Especially if they are a property). Or maybe there is a better solution, opinions welcome. Bye, bearophileFWIW I've encountered this thingy while messing with phobos std.file around a year ago. Still allowed and mishandled it seems. -- Dmitry Olshansky
Feb 25 2012