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