From c4192e855e4fefe6e40e62d7994decce47d21fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Louren=C3=A7o?= Date: Wed, 4 Jan 2023 21:36:46 +0000 Subject: [PATCH] fix(format.read): formattedRead incorrectly static asserts with Tuple and compile-time format string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This method supports std.typecons.Tuple, however, when passing the format string at compile-time, the format validation does not correctly account for the std.typecons.Tuple's types and instead validates the std.typecons.Tuple itself leading to a static assert. This change now adds support for this feature when used with compile-time format strings. Fix Issue #23600 Signed-off-by: João Lourenço --- std/format/read.d | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/std/format/read.d b/std/format/read.d index 144fa8c0d..44d65eb64 100644 --- a/std/format/read.d +++ b/std/format/read.d @@ -303,8 +303,23 @@ uint formattedRead(alias fmt, Range, Args...)(auto ref Range r, auto ref Args ar if (isSomeString!(typeof(fmt))) { import std.format : checkFormatException; + import std.meta : staticMap; + import std.typecons : Tuple; - alias e = checkFormatException!(fmt, Args); + + // formattedRead supports std.typecons.Tuple + // however, checkFormatException does not + // this means that all std.typecons.Tuple's types in Args must be unwrapped + // and passed to checkFormatException + template Flatten(T) + { + static if (is(T : Tuple!Args, Args...)) + alias Flatten = Args; + else + alias Flatten = T; + } + + alias e = checkFormatException!(fmt, staticMap!(Flatten, Args)); static assert(!e, e); return .formattedRead(r, fmt, args); }