From 0ca50877374489ee4639afe29cd656abcfc0d5ba Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 7 Dec 2017 15:06:28 +0000 Subject: [PATCH] fix Issue 18044 - std.conv.to for implicitly convertible associative arrays --- std/conv.d | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/std/conv.d b/std/conv.d index 6cfff14158f..6277c32580d 100644 --- a/std/conv.d +++ b/std/conv.d @@ -1573,7 +1573,7 @@ Associative array to associative array conversion converts each key and each value in turn. */ private T toImpl(T, S)(S value) -if (isAssociativeArray!S && +if (!isImplicitlyConvertible!(S, T) && isAssociativeArray!S && isAssociativeArray!T && !is(T == enum)) { /* This code is potentially unsafe. @@ -1619,6 +1619,16 @@ if (isAssociativeArray!S && auto d = to!(immutable(short[immutable wstring])[immutable string[double[]]])(c); } +@safe unittest +{ + import std.algorithm.comparison : equal; + import std.array : byPair; + + int[int] a; + assert(a.to!(int[int]) == a); + assert(a.to!(const(int)[int]).byPair.equal(a.byPair)); +} + private void testIntegralToFloating(Integral, Floating)() { Integral a = 42;