Bug 21768 – typeid(Expression) doesn't properly resolve opIndex overload

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-03-25T18:22:53Z
Last change time
2024-12-13T19:15:30Z
Assigned to
No Owner
Creator
blackbirdcry806
Moved to GitHub: dmd#19897 →

Comments

Comment #0 by blackbirdcry806 — 2021-03-25T18:22:53Z
When using the typeid(Expression) statement where "Expression" is a membership access of a struct that is returned by a opIndex oveload that takes only one parameter, the compiler resolve it as an array access instead of a opIndex call. Adding parenthesis around the expression solve the problem but looks inconsistent. godbolt link: https://godbolt.org/z/djjxqvKr8 sample code (same as above): struct Vec2 { int x, y; } class Entity { } struct Tile { Entity e; } class World { auto opIndex(Vec2 i) { return Tile(); } auto opIndex(int i, int j) { return Tile(); } auto opIndex(int i) { return Tile(); } } void main() { auto w = new World(); // auto id = typeid(w[Vec2(0, 0)].e); // compile error here // auto id4 = typeid(w[0].e); // error as well // works fine auto id2 = typeid((w[Vec2(0, 0)].e)); auto id3 = typeid(w[0, 0].e); }
Comment #1 by moonlightsentinel — 2021-03-26T11:42:15Z
Comment #2 by robert.schadek — 2024-12-13T19:15:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19897 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB