Bug in tuple comparison?

Magnus Lie Hetland magnus at hetland.org
Thu Mar 24 09:39:08 PDT 2011


I guess this is getting old by now ... but I've come across yet another bug :->

This one is a bit obscure, and deals with comparing tuples in 
contracts. It seems that some type information about the result is lost 
when entering an out-block, or something. At least, DMD (2.052, OS X) 
is unable to infer types properly, and is therefore unable to compare 
tuples in some cases. Sample program follows. (Similar behavior occurs 
for other comparison operators as well.)

import std.typecons;
T[] func(T)(T[] arg)
out(result) {
    auto a = result[0];
    auto b = arg[0];
    auto c = result[0];
    // assert(c < a); // Doesn't work
    // assert(a < c); // Doesn't work
    // assert(c < b); // Doesn't work
    assert(b < c); // Works
}
body {
    return arg;
}
void main() {
    alias Tuple!(real, uint) Entry;
    func(new Entry[100]);
}

The error (when uncommenting one of the lines that don't work, e.g., 
line 7) is:

tuplecmpbug.d(7): Error: template 
std.typecons.Tuple!(real,uint).Tuple.opCmp(R) if (isTuple!(R)) does not 
match any function template declaration
tuplecmpbug.d(7): Error: template 
std.typecons.Tuple!(real,uint).Tuple.opCmp(R) if (isTuple!(R)) cannot 
deduce template function from argument types 
!()(const(Tuple!(real,uint)))

I take it this is a bug (or am I just missing something)? Is it a known 
bug? (Sorry if it's in the tracker; it can be hard to find equivalents 
there...)

-- 
Magnus Lie Hetland
http://hetland.org



More information about the Digitalmars-d-learn mailing list