Bug 7449 – Algebraic's operator[] is incorrect

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-05T20:26:58Z
Last change time
2020-03-21T03:56:37Z
Assigned to
No Owner
Creator
Andrei Alexandrescu

Comments

Comment #0 by andrei — 2012-02-05T20:26:58Z
import std.variant; import std.stdio; void main() { int[string] o; o["foo"] = 42; Variant a = o; Algebraic!(int[string], string) b = o; writeln(a["foo"]); writeln(b["foo"]); } The last line fails at runtime with an exception.
Comment #1 by andrei — 2012-02-05T20:27:44Z
Hans Fugal identified this blames to revision 3a1f9109, this snippet: @@ -313,20 +364,23 @@ private: case OpID.index: auto me = cast(A*) pStore; - static if (isArray!(A)) + // Added allowed!(...) prompted by a bug report by Chris + // Nicholson-Sauls. + static if (isArray!(A) && allowed!(typeof(A.init[0]))) { // array type; input and output are the same VariantN auto result = cast(VariantN*) parm; size_t index = result.convertsTo!(int) ? result.get!(int) : result.get!(size_t); *result = (*me)[index]; - break; + break; } - else static if (isAssociativeArray!(A)) + else static if (isAssociativeArray!(A) + && allowed!(typeof(A.init.values[0]))) { auto result = cast(VariantN*) parm; *result = (*me)[result.get!(typeof(A.keys[0]))]; - break; + break; } else {
Comment #2 by public — 2014-08-23T01:51:52Z
*** Issue 13354 has been marked as a duplicate of this issue. ***
Comment #3 by b2.temp — 2015-12-07T01:56:42Z
a dup of this one is resolved fixed.