From d86c1f605995b423dd1a467b2c1c530dc52adb1e Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Fri, 9 Oct 2020 15:07:14 +0000 Subject: [PATCH] Fix issue 13930, 19345 - Fix receiveOnly for non-assignable types --- std/concurrency.d | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/std/concurrency.d b/std/concurrency.d index e63ac97379d..84d677a6189 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -802,7 +802,17 @@ do thisInfo.ident.mbox.get((T val) { static if (T.length) - ret.field = val; + { + static if (isAssignable!T) + { + ret.field = val; + } + else + { + import core.lifetime : emplace; + emplace(&ret, val); + } + } }, (LinkTerminated e) { throw e; }, (OwnerTerminated e) { throw e; }, @@ -2727,3 +2737,27 @@ auto ref initOnce(alias var)(lazy typeof(var) init, Mutex mutex) receiveOnly!(bool); assert(x[0] == 5); } + +// https://issues.dlang.org/show_bug.cgi?id=13930 +@system unittest +{ + immutable aa = ["0":0]; + thisTid.send(aa); + receiveOnly!(immutable int[string]); // compile error +} + +// https://issues.dlang.org/show_bug.cgi?id=19345 +@system unittest +{ + static struct Aggregate { const int a; const int[5] b; } + static void t1(Tid mainTid) + { + const sendMe = Aggregate(42, [1, 2, 3, 4, 5]); + mainTid.send(sendMe); + } + + spawn(&t1, thisTid); + auto result1 = receiveOnly!(const Aggregate)(); + immutable expected = Aggregate(42, [1, 2, 3, 4, 5]); + assert(result1 == expected); +}