From 7d282bda2ae8c679381e67d4089306234b1d042e Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Tue, 26 Nov 2024 11:39:54 +0100 Subject: [PATCH] Fix bugzilla 24883 - Speculative template overload error escapes with `-preview=rvaluerefparam` --- compiler/src/dmd/templatesem.d | 8 +++++++- compiler/test/compilable/rvalueref.d | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/src/dmd/templatesem.d b/compiler/src/dmd/templatesem.d index bd3674a8cc82..0e9c4338a052 100644 --- a/compiler/src/dmd/templatesem.d +++ b/compiler/src/dmd/templatesem.d @@ -1252,7 +1252,13 @@ extern (D) MATCHpair deduceFunctionTemplateMatch(TemplateDeclaration td, Templat //printf("farg = %s %s\n", farg.type.toChars(), farg.toChars()); RootObject oarg = farg; - if ((fparam.storageClass & STC.ref_) && (!(fparam.storageClass & STC.auto_) || farg.isLvalue())) + + if (farg.isFuncExp()) + { + // When assigning an untyped (void) lambda `x => y` to a `(F)(ref F)` parameter, + // we don't want to deduce type void creating a void parameter + } + else if ((fparam.storageClass & STC.ref_) && (!(fparam.storageClass & STC.auto_) || farg.isLvalue())) { /* Allow expressions that have CT-known boundaries and type [] to match with [dim] */ diff --git a/compiler/test/compilable/rvalueref.d b/compiler/test/compilable/rvalueref.d index 1c96c36f1f5b..eace6ee47fe3 100644 --- a/compiler/test/compilable/rvalueref.d +++ b/compiler/test/compilable/rvalueref.d @@ -11,3 +11,9 @@ struct AS void popFront(ref string) { } static assert(!is(typeof((R r) => r.popFront))); + +// https://issues.dlang.org/show_bug.cgi?id=24883 +int toString(Writer)(ref Writer sink) => 3; +int toString(void delegate(scope const(char)[]) sink) => 4; +void put() {} +pragma(msg, toString(dst => put()));