Bug 4441 – TDPL Example on P401 & 402 doesn't compile on D2.047, 2.046, 2.045, 2.044. Seems to be a problem involves tuples and []
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2010-07-09T14:52:00Z
Last change time
2010-11-01T13:35:50Z
Assigned to
nobody
Creator
gareth.tpc
Comments
Comment #0 by gareth.tpc — 2010-07-09T14:52:07Z
The example:
import std.concurrency, std.stdio, std.contracts; /*std.contracts was missing in the book, but this is fairly trivial change*/
void main() {
auto low = 0, high = 100;
auto tid = spawn(&writer);
foreach(i; low .. high) {
writeln("Main thread: ",i);
tid.send(thisTid,i);
enforce(receiveOnly!Tid() == tid);
}
}
void writer() {
for(;;) {
auto msg = receiveOnly!(Tid,int)();
writeln("Secondary thread: ", msg[1]); //Line 17
msg[0].send(thisTid); //Line 18
}
}
thread_test.d(17): Error: no [] operator overload for type Tuple!(Tid,int)
thread_test.d(18): Error: no [] operator overload for type Tuple!(Tid,int)
Trying to compile with version 2.044-2.046 produces these errors
thread_test.d(10): Error: template std.typecons.Tuple!(Tid).Tuple.opEquals(T) if (is(typeof(T.field))) does not match any function template declaration
thread_test.d(10): Error: template std.typecons.Tuple!(Tid).Tuple.opEquals(T) if (is(typeof(T.field))) cannot deduce template function from argument types !()(Tid)
Comment #1 by gareth.tpc — 2010-07-09T15:09:57Z
Possible minimal case:
import std.typecons;
void main() {
Tuple!(int,int) x;
int y=x[0];
}
thread_test.d(5): Error: no [] operator overload for type Tuple!(int,int)
Comment #2 by andrei — 2010-07-09T18:55:20Z
This is one big reason for the introduction of alias this. However, there was never time to fix it. I agree it's a major bug.