Bug 14236 – opIndex... and opIndex fallback

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-02T15:30:32Z
Last change time
2024-12-13T18:40:43Z
Assigned to
No Owner
Creator
John Colvin
Moved to GitHub: dmd#18949 →

Comments

Comment #0 by john.loughran.colvin — 2015-03-02T15:30:32Z
struct S { auto opIndex(size_t i) { return 1; } auto opIndexUnary(string s)(size_t i, size_t j) { return -1; } } unittest { S s; assert(-s[0] == -1); } this fails to compile because the compiler won't fall back to using opIndex when it can't find an applicable opIndexUnary
Comment #1 by john.loughran.colvin — 2015-03-02T16:12:37Z
The same goes for opIndexAssign, opIndexOpAssign and so on... Once you define one possible overload, nothing will fall back to using opIndex and then applying the operation to the result.
Comment #2 by robert.schadek — 2024-12-13T18:40:43Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18949 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB