Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved error message when an assocArray can't be created #7002

Merged
merged 1 commit into from
May 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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"]);
Expand Down