www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug w/tuple of custom types?

reply Magnus Lie Hetland <magnus hetland.org> writes:
Sample program:

import std.typecons;

typedef uint oid_t;

void main() {
    Tuple!(uint,uint) key;
    // Tuple!(oid_t,oid_t) key; // Doesn't work
}

If I use the last tuple instead of the first, I get the following 
compiler error with DMD 2.052 in OS X:

/path/to/src/phobos/std/format.d(1579): Error: function 
std.format.formatValue!(Appender!(string),oid_t,immutable(char)).formatValue 
is deprecated
/path/to/src/phobos/std/format.d(306): Error: template instance 
std.format.formatGeneric!(Appender!(string),oid_t,immutable(char)) 
error instantiating
/path/to/src/phobos/std/typecons.d(507):        instantiated from here: 
formattedWrite!(Appender!(string),immutable(char),oid_t)

It seems that std.typecons is using a deprecated formatting API, which 
is triggered by my use of a custom type? And ... I guess this would be 
a bug? (I looked in the tracker, and couldn't find it there already.)

-- 
Magnus Lie Hetland
http://hetland.org
Mar 21 2011
next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 21 Mar 2011 13:03:25 -0400, Magnus Lie Hetland  
<magnus hetland.org> wrote:

 Sample program:

 import std.typecons;

 typedef uint oid_t;

 void main() {
     Tuple!(uint,uint) key;
     // Tuple!(oid_t,oid_t) key; // Doesn't work
 }

 If I use the last tuple instead of the first, I get the following  
 compiler error with DMD 2.052 in OS X:

 /path/to/src/phobos/std/format.d(1579): Error: function  
 std.format.formatValue!(Appender!(string),oid_t,immutable(char)).formatValue  
 is deprecated
 /path/to/src/phobos/std/format.d(306): Error: template instance  
 std.format.formatGeneric!(Appender!(string),oid_t,immutable(char)) error  
 instantiating
 /path/to/src/phobos/std/typecons.d(507):        instantiated from here:  
 formattedWrite!(Appender!(string),immutable(char),oid_t)

 It seems that std.typecons is using a deprecated formatting API, which  
 is triggered by my use of a custom type? And ... I guess this would be a  
 bug? (I looked in the tracker, and couldn't find it there already.)

If you looked and couldn't find it, it doesn't hurt to add it. Worst case -- it gets marked as a duplicate. Note that typedef is eventually going to be deprecated. I'd suggest using alias unless you have a need to force uints not to be castable to oid_t. -Steve
Mar 21 2011
next sibling parent reply Magnus Lie Hetland <magnus hetland.org> writes:
On 2011-03-21 18:40:07 +0100, Steven Schveighoffer said:

 If you looked and couldn't find it, it doesn't hurt to add it.  Worst 
 case -- it gets marked as a duplicate.

OK. Perhaps I should just start doing that, rather than asking here about every bug I find. (I seem to come across new ones every day ;-)
 Note that typedef is eventually going to be deprecated.  I'd suggest 
 using alias unless you have a need to force uints not to be castable to 
 oid_t.

Ah. That sort of makes the bug a bit less relevant :-> Actually, the typedef *was* to prevent that casting, because I inadvertently used an uint that was of a semantically different kind, and got a hard-to-spot bug -- so I thought I'd try to prevent that by using the type system. Any way to do that without (to be deprecated) typedef? -- Magnus Lie Hetland http://hetland.org
Mar 23 2011
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Magnus Lie Hetland:

 Any way to do that without (to be deprecated) typedef?

At the moment with a struct that contains an "alias this", I presume... Bye, bearophile
Mar 23 2011
prev sibling parent Bekenn <leaveme alone.com> writes:
On 3/23/2011 12:45 PM, Magnus Lie Hetland wrote:
 Any way to do that without (to be deprecated) typedef?

Nothing pretty, at least not yet. bearophile's suggestion is about as close as you can get right now.
Mar 24 2011
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 23 Mar 2011 16:14:55 -0400, bearophile <bearophileHUGS lycos.com>  
wrote:

 Magnus Lie Hetland:

 Any way to do that without (to be deprecated) typedef?

At the moment with a struct that contains an "alias this", I presume...

And the alias this must point to a getter property to avoid the problem of implicitly casting from the base type to the specialized one. -Steve
Mar 24 2011
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
 Sample program:
 
 import std.typecons;
 
 typedef uint oid_t;
 
 void main() {
     Tuple!(uint,uint) key;
     // Tuple!(oid_t,oid_t) key; // Doesn't work
 }
 
 If I use the last tuple instead of the first, I get the following
 compiler error with DMD 2.052 in OS X:
 
 /path/to/src/phobos/std/format.d(1579): Error: function
 std.format.formatValue!(Appender!(string),oid_t,immutable(char)).formatValu
 e is deprecated
 /path/to/src/phobos/std/format.d(306): Error: template instance
 std.format.formatGeneric!(Appender!(string),oid_t,immutable(char))
 error instantiating
 /path/to/src/phobos/std/typecons.d(507):        instantiated from here:
 formattedWrite!(Appender!(string),immutable(char),oid_t)
 
 It seems that std.typecons is using a deprecated formatting API, which
 is triggered by my use of a custom type? And ... I guess this would be
 a bug? (I looked in the tracker, and couldn't find it there already.)

I would point out that typedef is going to be removed from the language. You should be using alias instead. I don't know if this wil lhave any effect on the bug you're seeing though (probably, since alias doesn't actually produce a new type - just an alias for the old one). - Jonathan M Davis
Mar 21 2011