Bug 10064 – opDollar called on garbage

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-10T18:15:00Z
Last change time
2013-07-11T15:32:57Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2013-05-10T18:15:14Z
This module unittest fails when module is in a project but runs fine as a singe file so one have to look at the generated instructions to see the bug: --- struct S { size_t[5] arr; @property size_t opDollar() // line 5 { return 0; } int opIndex(size_t index) { return 0; } } interface I { final S getS() { return S(); } } class C: I { this(in size_t[]) { } } unittest { auto i = cast(I) new C([0]); i.getS()[$]; // Causes `null this` at line 5 } ---
Comment #1 by verylonglogin.reg — 2013-06-13T04:28:03Z
I was incorrect about the issue source. `opDollar` is just called on a garbage: --- struct S { int x = 3; @disable this(); this(int) { x = 7; } int opSlice(size_t, size_t) { return 0; } @property size_t opDollar() { assert(x == 7 || x == 3); // fails assert(x == 7); return 0; } } void main() { auto x = S(0)[0 .. $]; } --- As a result e.g. this will fail too: --- import std.range; void main() { auto x = zip([1])[$ - 1]; } ---
Comment #2 by k.hara.pg — 2013-07-10T02:58:03Z
Comment #3 by github-bugzilla — 2013-07-11T15:32:44Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/c426980fd31433c0bbc182a1f9cc9476fe625278 fix Issue 10064 - opDollar called on garbage https://github.com/D-Programming-Language/dmd/commit/33ce37d6495aad7a3d6644392cf47e1af9d9d493 Merge pull request #2331 from 9rnsr/fix10064 Issue 10064 - opDollar called on garbage