Bug 13354 – Algebraic.opIndex/opIndexAssign makes wrong assumptions on the index/value type

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2014-08-22T10:24:00Z
Last change time
2014-09-06T16:44:41Z
Keywords
pull
Assigned to
nobody
Creator
sludwig

Comments

Comment #0 by sludwig — 2014-08-22T10:24:37Z
Currently both, the index and the value type for VariantN.opIndex(Assign) must be allowed!T. This is an unreasonable assumption for Algebraic and examples such as the following do not work because of this: --- alias T = Algebraic!(int[string], int[]); T v = ["a": 1, "b": 2]; assert(v["a"] == 1); // error v["a"] = 0; // error ---
Comment #1 by sludwig — 2014-08-22T10:41:38Z
Comment #2 by public — 2014-08-23T01:38:11Z
For the reference, error is "Error: static assert "Cannot store a string in a VariantN!(16LU, int[string], int[])""
Comment #3 by public — 2014-08-23T01:51:52Z
*** This issue has been marked as a duplicate of issue 7449 ***
Comment #4 by github-bugzilla — 2014-09-06T16:44:40Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/352dee3a8961f6b0403ae781145b8e3d881ab447 Fix issue #13354 - Use a generic Variant for passing opIndex/opIndexAssign arguments. Also improves the error message when an incompatible index or value type is used by printing the actual type ID instead of "void[]" in the thrown exception. https://github.com/D-Programming-Language/phobos/commit/9c8a1a5dfed7f0dc29c22da936fe964f0042562e Merge pull request #2453 from s-ludwig/issue_13354 Fix issue #13354 - Use a generic Variant for passing opIndex/opIndexAssign arguments.