Bug 23740 – Alias breaks valid array operation code using operator overloading

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2023-02-25T17:33:38Z
Last change time
2024-12-13T19:27:24Z
Assigned to
No Owner
Creator
HuskyNator
Moved to GitHub: dmd#20236 →

Comments

Comment #0 by HuskyNator — 2023-02-25T17:33:38Z
When an alias introduces a potential array, it's picked over a valid overloaded operator when doing an array operation, causing a compilation error. (Note this issue reminds of issue #3064) 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); }
Comment #1 by robert.schadek — 2024-12-13T19:27:24Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20236 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB