digitalmars.D.bugs - [Issue 11648] New: rangeerror when adding element to associative array and value is implicitely converted by alias this
- d-bugmail puremagic.com (35/35) Nov 30 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11648
- d-bugmail puremagic.com (22/44) Nov 30 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11648
- d-bugmail puremagic.com (6/6) Nov 30 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11648
https://d.puremagic.com/issues/show_bug.cgi?id=11648 Summary: rangeerror when adding element to associative array and value is implicitely converted by alias this Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: wrong-code Severity: regression Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: r.sagitario gmx.de PST --- dmd 2.063 compiles and runs this code correctly: ////////////////// import std.stdio; struct S { int _payload; alias _payload this; } void main() { S[string] symbols; symbols["a"] = 1; // works if using S(1) writeln(symbols); // ["a":1] } //////////////// but dmd 2.064 causes a range error when executing: core.exception.RangeError test(12): Range violation -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 30 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11648 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALIDdmd 2.063 compiles and runs this code correctly: ////////////////// import std.stdio; struct S { int _payload; alias _payload this; } void main() { S[string] symbols; symbols["a"] = 1; // works if using S(1) writeln(symbols); // ["a":1] } //////////////// but dmd 2.064 causes a range error when executing: core.exception.RangeError test(12): Range violationThis is intended behavior introduce by fixing bug 6178. Test case in compiler test suite. https://github.com/D-Programming-Language/dmd/pull/2539/files#diff-a137107b45f82e7d3b516e2aff79f1d5R940 First, 'alias this' does not work for object construction. struct S { int val; alias val this; } S s = 1; // compile error And in your case, AA does not have a storage corresponding to the key "a" yet. So, `symbols["a"] = 1;` should invoke _construction of S from integer 1_. But as I shown, S cannot construct from int. So, compiler always treat the line as _an assignment through alias this_. And of course, if the specified key does not exist in AA, the indexing should throw RangeError. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 30 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11648 PST --- Thanks for explanation. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 30 2013