digitalmars.D.bugs - [Issue 23740] New: Alias breaks valid array operation code using
- d-bugmail puremagic.com (40/40) Feb 25 2023 https://issues.dlang.org/show_bug.cgi?id=23740
https://issues.dlang.org/show_bug.cgi?id=23740 Issue ID: 23740 Summary: Alias breaks valid array operation code using operator overloading Product: D Version: D2 Hardware: x86_64 OS: Windows Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: HuskyNator protonmail.ch When an alias introduces a potential array, it's picked over a valid overloaded operator when doing an array operation, causing a compilation error. When the alias is removed, this code compiles and functions properly: struct Vec{ int[2] list; alias list this; // Causes failing compilation (c[]*b has b cast to int[2]). Vec opBinary(string op)(const Vec rhs) const { Vec newA; mixin("newA.list[0] = list[0]"~op~"rhs.list[0];"); mixin("newA.list[1] = list[1]"~op~"rhs.list[1];"); return newA; } } void main(string[]) { Vec a; a.list = [1,1]; Vec b; b.list = [2,2]; Vec[2] c = [a, b]; Vec[2] d; d[] = c[] * b; writeln(d); } --
Feb 25 2023