Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
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
80 changes: 72 additions & 8 deletions src/object.d
Original file line number Diff line number Diff line change
Expand Up @@ -3005,8 +3005,10 @@ Key[] keys(T : Value[Key], Value, Key)(T aa) @property
alias realAA = aa;
else
const(Value[Key]) realAA = aa;
auto a = cast(void[])_aaKeys(*cast(inout(AA)*)&realAA, Key.sizeof, typeid(Key[]));
auto res = *cast(Key[]*)&a;
auto res = () @trusted {
auto a = cast(void[])_aaKeys(*cast(inout(AA)*)&realAA, Key.sizeof, typeid(Key[]));
return *cast(Key[]*)&a;
}();
static if (__traits(hasPostblit, Key))
_doPostblit(res);
return res;
Expand All @@ -3019,7 +3021,7 @@ Key[] keys(T : Value[Key], Value, Key)(T *aa) @property
}

///
@system unittest
@safe unittest
{
auto aa = [1: "v1", 2: "v2"];
int sum;
Expand All @@ -3029,7 +3031,7 @@ Key[] keys(T : Value[Key], Value, Key)(T *aa) @property
assert(sum == 3);
}

@system unittest
@safe unittest
{
static struct S
{
Expand All @@ -3042,6 +3044,36 @@ Key[] keys(T : Value[Key], Value, Key)(T *aa) @property
assert(s.keys.length == 0);
}

@safe unittest
{
@safe static struct Key
{
string str;
this(this) @safe {}
}
string[Key] aa;
static assert(__traits(compiles, {
void test() @safe {
const _ = aa.keys;
}
}));
}

@safe unittest
{
static struct Key
{
string str;
this(this) @system {}
}
string[Key] aa;
static assert(!__traits(compiles, {
void test() @safe {
const _ = aa.keys;
}
}));
}

/***********************************
* Returns a dynamic array, the elements of which are the values in the
* associative array.
Expand All @@ -3057,8 +3089,10 @@ Value[] values(T : Value[Key], Value, Key)(T aa) @property
alias realAA = aa;
else
const(Value[Key]) realAA = aa;
auto a = cast(void[])_aaValues(*cast(inout(AA)*)&realAA, Key.sizeof, Value.sizeof, typeid(Value[]));
auto res = *cast(Value[]*)&a;
auto res = () @trusted {
auto a = cast(void[])_aaValues(*cast(inout(AA)*)&realAA, Key.sizeof, Value.sizeof, typeid(Value[]));
return *cast(Value[]*)&a;
}();
static if (__traits(hasPostblit, Value))
_doPostblit(res);
return res;
Expand All @@ -3071,7 +3105,7 @@ Value[] values(T : Value[Key], Value, Key)(T *aa) @property
}

///
@system unittest
@safe unittest
{
auto aa = ["k1": 1, "k2": 2];
int sum;
Expand All @@ -3081,7 +3115,7 @@ Value[] values(T : Value[Key], Value, Key)(T *aa) @property
assert(sum == 3);
}

@system unittest
@safe unittest
{
static struct S
{
Expand All @@ -3094,6 +3128,36 @@ Value[] values(T : Value[Key], Value, Key)(T *aa) @property
assert(s.values.length == 0);
}

@safe unittest
{
@safe static struct Value
{
string str;
this(this) @safe {}
}
Value[string] aa;
static assert(__traits(compiles, {
void test() @safe {
const _ = aa.values;
}
}));
}

@safe unittest
{
static struct Value
{
string str;
this(this) @system {}
}
Value[string] aa;
static assert(!__traits(compiles, {
void test() @safe {
const _ = aa.values;
}
}));
}

/***********************************
* Looks up key; if it exists returns corresponding value else evaluates and
* returns defaultValue.
Expand Down