D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 16974 - [REG2.068] Equal associative arrays with associative array keys are considered unequal
Summary: [REG2.068] Equal associative arrays with associative array keys are considere...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2016-12-15 16:13 UTC by Denis Shelomovskii
Modified: 2017-01-16 23:24 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2016-12-15 16:13:35 UTC
This code should run fine:
---
void main()
{
    int[int] a = [1 : 2];
    assert([a : 3] == [a : 3]);        // fails
    assert([a : 3] == [[1 : 2] : 3]);  // fails
}
---
Comment 1 Denis Shelomovskii 2016-12-15 16:26:12 UTC
The reason is incorrect hash calculation:
---
int[int] a = [1 : 2];
assert(typeid(a).getHash(&a) == typeid(a).getHash(&a)); // fails
---

Opened druntime pull 1715 [1].

This incorrect hash calculation became possible because of `hashOf` signature, see Issue 16973.

[1] https://github.com/dlang/druntime/pull/1715
Comment 2 safety0ff.bugz 2016-12-16 02:09:56 UTC
You've marked this as a regression, which version did this previously work in?
Comment 3 Denis Shelomovskii 2016-12-16 10:24:14 UTC
(In reply to safety0ff.bugz from comment #2)
> You've marked this as a regression, which version did this previously work
> in?

Because at least before 79bc91b41334c1805f557ef2f1606de31c6764d1 [1] `rt.util.hash.hashOf` was used in `_aaGetHash`. Though I didn't actually test it.

[1] https://github.com/dlang/druntime/commit/79bc91b41334c1805f557ef2f1606de31c6764d1
Comment 4 Denis Shelomovskii 2016-12-16 12:59:29 UTC
(In reply to Denis Shelomovskii from comment #3)
> Though I didn't actually

My friend's code which worked around 2.5 years ago is now broken.
Comment 5 safety0ff.bugz 2016-12-16 16:25:03 UTC
(In reply to Denis Shelomovskii from comment #3)
> 
> Because at least before 79bc91b41334c1805f557ef2f1606de31c6764d1 [1]
> `rt.util.hash.hashOf` was used in `_aaGetHash`. Though I didn't actually
> test it.

Ah, yea, I see the import was removed, good enough for me.
Comment 6 github-bugzilla 2016-12-28 00:09:57 UTC
Commits pushed to stable at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/5cc28431b92d6849ef7758d200f714f5aee996f3
Fix Issue 16974 - Equal associative arrays with associative array keys are considered unequal

Use correct overload of `hashOf` in `_aaGetHash`.

This incorrect usage is possible because of Issue 16973 - `hashOf` has error-prone signature as `(T, seed)` may be confused with `(ptr, length)` [1].

[1] https://issues.dlang.org/show_bug.cgi?id=16973

https://github.com/dlang/druntime/commit/d57fdb116ebb9dc1a7c0f1983c253db58dbbc22b
Merge pull request #1715 from denis-sh/fix-Issue-16974

[REG2.068] Fix Issue 16974 - Equal associative arrays with associative array keys are considered unequal
Comment 7 github-bugzilla 2017-01-15 02:36:21 UTC
Commits pushed to master at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/5cc28431b92d6849ef7758d200f714f5aee996f3
Fix Issue 16974 - Equal associative arrays with associative array keys are considered unequal

https://github.com/dlang/druntime/commit/d57fdb116ebb9dc1a7c0f1983c253db58dbbc22b
Merge pull request #1715 from denis-sh/fix-Issue-16974
Comment 8 github-bugzilla 2017-01-16 23:24:45 UTC
Commits pushed to newCTFE at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/5cc28431b92d6849ef7758d200f714f5aee996f3
Fix Issue 16974 - Equal associative arrays with associative array keys are considered unequal

https://github.com/dlang/druntime/commit/d57fdb116ebb9dc1a7c0f1983c253db58dbbc22b
Merge pull request #1715 from denis-sh/fix-Issue-16974