From b4756c2f5f01364f78d91d38124b4a873da40e2e Mon Sep 17 00:00:00 2001 From: Marco de Wild Date: Sun, 12 May 2019 00:19:38 +0200 Subject: [PATCH] Improved error message when an assocArray can't be created --- std/array.d | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/std/array.d b/std/array.d index aa6c28bc5f7..dfb4f76c5a7 100644 --- a/std/array.d +++ b/std/array.d @@ -442,7 +442,8 @@ if (isInputRange!Range) import std.typecons : isTuple; alias E = ElementType!Range; - static assert(isTuple!E, "assocArray: argument must be a range of tuples"); + static assert(isTuple!E, "assocArray: argument must be a range of tuples," + ~" but was a range of "~E.stringof); static assert(E.length == 2, "assocArray: tuple dimension must be 2"); alias KeyType = E.Types[0]; alias ValueType = E.Types[1]; @@ -552,6 +553,7 @@ if (isInputRange!Values && isInputRange!Keys) @safe unittest { import std.typecons; + static assert(!__traits(compiles, [ 1, 2, 3 ].assocArray())); static assert(!__traits(compiles, [ tuple("foo", "bar", "baz") ].assocArray())); static assert(!__traits(compiles, [ tuple("foo") ].assocArray())); assert([ tuple("foo", "bar") ].assocArray() == ["foo": "bar"]);