Skip to content

Commit 0ca5087

Browse files
committed
fix Issue 18044 - std.conv.to for implicitly convertible associative arrays
1 parent 14322ea commit 0ca5087

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

std/conv.d

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ Associative array to associative array conversion converts each key
15731573
and each value in turn.
15741574
*/
15751575
private T toImpl(T, S)(S value)
1576-
if (isAssociativeArray!S &&
1576+
if (!isImplicitlyConvertible!(S, T) && isAssociativeArray!S &&
15771577
isAssociativeArray!T && !is(T == enum))
15781578
{
15791579
/* This code is potentially unsafe.
@@ -1619,6 +1619,16 @@ if (isAssociativeArray!S &&
16191619
auto d = to!(immutable(short[immutable wstring])[immutable string[double[]]])(c);
16201620
}
16211621

1622+
@safe unittest
1623+
{
1624+
import std.algorithm.comparison : equal;
1625+
import std.array : byPair;
1626+
1627+
int[int] a;
1628+
assert(a.to!(int[int]) == a);
1629+
assert(a.to!(const(int)[int]).byPair.equal(a.byPair));
1630+
}
1631+
16221632
private void testIntegralToFloating(Integral, Floating)()
16231633
{
16241634
Integral a = 42;

0 commit comments

Comments
 (0)