Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit f60615f

Browse files
authored
Merge pull request #2323 from n8sh/issue-19262
Fix Issue 19262 - hashOf associative array should infer nothrow merged-on-behalf-of: Nathan Sashihara <n8sh@users.noreply.github.com>
2 parents 17bfde3 + 050ad81 commit f60615f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/core/internal/hash.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,10 @@ if (!is(T == enum) && (is(T == interface) || is(T == class))
606606
//associative array hash. CTFE depends on base types
607607
size_t hashOf(T)(T aa) if (!is(T == enum) && __traits(isAssociativeArray, T))
608608
{
609+
static if (is(typeof(aa) : V[K], K, V)) {} // Put K & V in scope.
610+
static if (__traits(compiles, (ref K k, ref V v) nothrow => .hashOf(k) + .hashOf(v)))
611+
scope (failure) assert(0); // Allow compiler to infer nothrow.
612+
609613
if (!aa.length) return 0;
610614
size_t h = 0;
611615

test/hash/src/test_hash.d

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ void main()
66
issue18918();
77
issue18925();
88
issue19005();
9+
issue19262();
910
issue19282();
1011
testTypeInfoArrayGetHash1();
1112
testTypeInfoArrayGetHash2();
@@ -86,6 +87,14 @@ void issue19005() @nogc nothrow pure @safe
8687
auto hash = date.hashOf;
8788
}
8889

90+
/// hashOf associative array should infer nothrow
91+
void issue19262() nothrow
92+
{
93+
int[int] aa;
94+
auto h = hashOf(aa);
95+
h = hashOf(aa, h);
96+
}
97+
8998
extern(C++) class Issue19282CppClass {}
9099

91100
/// test that hashOf doesn't crash for non-null C++ objects.

0 commit comments

Comments
 (0)