Bug 20954 – spawn in unitest: compiler error, confusing message

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-18T22:41:42Z
Last change time
2020-06-20T21:02:06Z
Assigned to
No Owner
Creator
mw

Attachments

IDFilenameSummaryContent-TypeSize
1794spawn_in_unittest.dspawn in unitest: compiler error, confusing messagetext/plain2081

Comments

Comment #0 by mingwu — 2020-06-18T22:41:42Z
Created attachment 1794 spawn in unitest: compiler error, confusing message put the code from: https://tour.dlang.org/tour/en/multithreading/synchronization-sharing in file, and put unittest block from safePrint() to main() as here: https://github.com/mingwugmail/dlang_tour/blob/master/spawn_in_unittest.d#L33 $ dmd -unittest spawn_in_unittest.d spawn_in_unittest.d(87): Error: template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(shared(SafeQueue!int) queue, shared(int)* queueCounter) @system, shared(SafeQueue!int), shared(int)*), candidates are: /usr/include/dmd/phobos/std/concurrency.d(460): spawn(F, T...)(F fn, T args) with F = void delegate(shared(SafeQueue!int), shared(int)*) @system, T = (shared(SafeQueue!int), shared(int)*) must satisfy the following constraint: isSpawnable!(F, T) spawn_in_unittest.d(88): Error: template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(Tid owner, shared(SafeQueue!int) queue, shared(int)* queueCounter) @system, Tid, shared(SafeQueue!int), shared(int)*), candidates are: /usr/include/dmd/phobos/std/concurrency.d(460): spawn(F, T...)(F fn, T args) with F = void delegate(Tid, shared(SafeQueue!int), shared(int)*) @system, T = (Tid, shared(SafeQueue!int), shared(int)*) must satisfy the following constraint: isSpawnable!(F, T)
Comment #1 by mingwu — 2020-06-20T21:02:06Z
need to add static to all the functions, including those called by the spawned functions: static void safePrint(T...)(T args)