digitalmars.D.learn - Bug? tupleof and const string = ""
- Andre (13/13) Feb 13 2014 Hi,
- Tobias Pankrath (6/19) Feb 13 2014 I'm not sure. May guess is the compiler figures that you'll never
- Andre (8/31) Feb 13 2014 It is strange, const string attributes without a value are working fine.
- bearophile (7/17) Feb 13 2014 Tupleeof is working correctly here. Currently const/immutable
- John Colvin (4/23) Feb 13 2014 Don't you mean const/immutable fields with initialisers don't
- Dicebot (13/16) Feb 13 2014 Yes, it is legacy behavior (== bug) that persisted since D1 days
- monarch_dodra (8/25) Feb 13 2014 To be anal, it's technically the same as:
- Andre (4/23) Feb 13 2014 Thanks for the info. Time to update to 2.065:)
Hi, could you have a look whether this is a bug with tupleof? In case you have a const string with a default value, the attribute is not in the tupleof list. struct A { const string a = "abc"; string d; } void main(){ assert(A().tupleof.length == 2); // fails -> length = 1 } Kind regards André
Feb 13 2014
On Thursday, 13 February 2014 at 16:37:20 UTC, Andre wrote:Hi, could you have a look whether this is a bug with tupleof? In case you have a const string with a default value, the attribute is not in the tupleof list. struct A { const string a = "abc"; string d; } void main(){ assert(A().tupleof.length == 2); // fails -> length = 1 } Kind regards AndréI'm not sure. May guess is the compiler figures that you'll never be able to change a and pulls it out of the struct. What I don't know is, if it should do this without using immutable or enum. Besides: I don't think that const elements make any sense. What do you want to do?
Feb 13 2014
Am 13.02.2014 17:42, schrieb Tobias Pankrath:On Thursday, 13 February 2014 at 16:37:20 UTC, Andre wrote:It is strange, const string attributes without a value are working fine. The use case is for communication with a database procedure. The database procedure want the request in JSON format. I created the structure similiar to the JSON request and serialize it to JSON. Some of the values should be constant others should be variable. Kind regards AndréHi, could you have a look whether this is a bug with tupleof? In case you have a const string with a default value, the attribute is not in the tupleof list. struct A { const string a = "abc"; string d; } void main(){ assert(A().tupleof.length == 2); // fails -> length = 1 } Kind regards AndréI'm not sure. May guess is the compiler figures that you'll never be able to change a and pulls it out of the struct. What I don't know is, if it should do this without using immutable or enum. Besides: I don't think that const elements make any sense. What do you want to do?
Feb 13 2014
Andre:could you have a look whether this is a bug with tupleof? In case you have a const string with a default value, the attribute is not in the tupleof list. struct A { const string a = "abc"; string d; } void main(){ assert(A().tupleof.length == 2); // fails -> length = 1 }Tupleeof is working correctly here. Currently const/immutable fields don't become struct instance fields. After a transition phase this will be changed, and in some months you will see two fields there. DMD 2.065 has a warning on this. Bye, bearophile
Feb 13 2014
On Thursday, 13 February 2014 at 16:52:58 UTC, bearophile wrote:Andre:Don't you mean const/immutable fields with initialisers don't become instance fields? Or is this actually as strange as it sounds?could you have a look whether this is a bug with tupleof? In case you have a const string with a default value, the attribute is not in the tupleof list. struct A { const string a = "abc"; string d; } void main(){ assert(A().tupleof.length == 2); // fails -> length = 1 }Tupleeof is working correctly here. Currently const/immutable fields don't become struct instance fields. After a transition phase this will be changed, and in some months you will see two fields there. DMD 2.065 has a warning on this. Bye, bearophile
Feb 13 2014
On Thursday, 13 February 2014 at 16:57:19 UTC, John Colvin wrote:Don't you mean const/immutable fields with initialisers don't become instance fields? Or is this actually as strange as it sounds?Yes, it is legacy behavior (== bug) that persisted since D1 days and was addressed only recently. Until this deprecation/transition process will end this: struct X { const string value = "literal"' } is effectively same as this: struct X { enum value = "literal"' }
Feb 13 2014
On Thursday, 13 February 2014 at 17:12:28 UTC, Dicebot wrote:On Thursday, 13 February 2014 at 16:57:19 UTC, John Colvin wrote:To be anal, it's technically the same as: struct X { static const string value = "literal"; } The immutable/const member will be made a static member, which you can deference, or pass by reference.Don't you mean const/immutable fields with initialisers don't become instance fields? Or is this actually as strange as it sounds?Yes, it is legacy behavior (== bug) that persisted since D1 days and was addressed only recently. Until this deprecation/transition process will end this: struct X { const string value = "literal"; } is effectively same as this: struct X { enum value = "literal"; }
Feb 13 2014
Am 13.02.2014 17:52, schrieb bearophile:Andre:Thanks for the info. Time to update to 2.065:) Kind regards Andrécould you have a look whether this is a bug with tupleof? In case you have a const string with a default value, the attribute is not in the tupleof list. struct A { const string a = "abc"; string d; } void main(){ assert(A().tupleof.length == 2); // fails -> length = 1 }Tupleeof is working correctly here. Currently const/immutable fields don't become struct instance fields. After a transition phase this will be changed, and in some months you will see two fields there. DMD 2.065 has a warning on this. Bye, bearophile
Feb 13 2014