Bug 20440 – Associative arrays with values whose opAssign doesn't return a ref don't support require function
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-12-09T15:17:00Z
Last change time
2019-12-11T23:54:32Z
Keywords
pull
Assigned to
No Owner
Creator
Jan Hönig
Comments
Comment #0 by hrominium — 2019-12-09T15:17:00Z
import std.bigint;
void main(){
BigInt[int] foo;
foo.require(0, BigInt.init);
}
Does not compile:
/usr/include/dmd/druntime/import/object.d(2600): Error: (*p).opAssign(value()) is not an lvalue and cannot be modified
test.d(4): Error: template instance object.require!(int, BigInt) error instantiating
Comment #1 by mipri — 2019-12-09T15:23:42Z
with v2.086.1, either of the following permits the test case to compile:
in phobos/std/bigint.d, add a 'ref' to the following return type:
/// Assignment from another BigInt.
BigInt opAssign(T:BigInt)(T x) pure @nogc
in druntime/import/object.d, change the last line of require from
return found ? *p : (*p = value);
to
if (!found) *p = value;
return *p;
Comment #2 by dlang-bot — 2019-12-09T16:05:44Z
@GoaLitiuM created dlang/phobos pull request #7312 "Fix Issue 20440 - Associative arrays of BigInt does not support require or get function" fixing this issue:
- Fix Issue 20440 - Associative arrays of BigInt does not support require or get function
https://github.com/dlang/phobos/pull/7312
Comment #3 by simen.kjaras — 2019-12-10T09:02:17Z
The fix in PR 7312 only fixes this for BigInt specifically. If we are not going to require that opAssign return ref for every type, this should be fixed in druntime instead.
In other words: this is a bug in require(), not in BigInt.
Comment #4 by dlang-bot — 2019-12-11T18:57:33Z
@n8sh created dlang/druntime pull request #2869 "Fix Issue 20440 - Associative arrays of BigInt does not support require or get function" fixing this issue:
- Fix Issue 20440 - Associative arrays of BigInt does not support require or get function
Applies to any type with a custom opAssign that doesn't return a ref to self
https://github.com/dlang/druntime/pull/2869
Comment #5 by n8sh.secondary — 2019-12-11T19:19:09Z
Adjusting title to be more general. Also it seems that `get` currently works with BigInt.
Comment #6 by dlang-bot — 2019-12-11T23:54:32Z
dlang/druntime pull request #2869 "Fix Issue 20440 - Associative arrays with values whose opAssign doesn't return a ref don't support require function" was merged into master:
- 35538a12511a1e98816dd846003cd9259d92f931 by Nathan Sashihara:
Fix Issue 20440 - Associative arrays with values whose opAssign doesn't return a ref don't support require function
https://github.com/dlang/druntime/pull/2869